我遇到一些阿拉伯文字的问题,我需要在字符串中 翻转 数字。所以这个:
"Some text written in 1982 by someone with m0123456 or 12-to-13"
应该成为:
"Some text written in 2891 by someone with m6543210 or 21-to-31"
正则表达式解决方案将是伟大的。对大字符串越优化越好。
任何提示?
答案 0 :(得分:1)
theText.replace(/\d+/g, function(s:String){ return s.split("").reverse().join(""); })
(免责声明:仅测试Javascript,而不是ActionScript。)
答案 1 :(得分:0)
谢谢@KennyTM!您的解决方案完美无缺(经过一些调整后)。
我只需要指定正则表达式模式的类型,并删除第3行中的strict参数类型(:String)
var theText = "Some text written in 1982 by someone with m0123456 or 12-to-13";
var pattern:RegExp = /\d+/g;
var result = theText.replace(pattern, function(s){ return s.split("").reverse().join("") })
trace(result); //Some text written in 2891 by someone with m6543210 or 21-to-31