Javascript 在字符串中翻转数字

Javascript 在字符串中翻转数字,javascript,regex,actionscript-3,string,Javascript,Regex,Actionscript 3,String,我对一些阿拉伯语文本有一个问题,我需要在字符串中翻转数字。因此: "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" 正则表达式解决方案将非常好。针对大型字符串进行的优化越多越好 有什么提示吗 theText.replace(/\d+/g, function(s:String)

我对一些阿拉伯语文本有一个问题,我需要在字符串中翻转数字。因此:

"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"
正则表达式解决方案将非常好。针对大型字符串进行的优化越多越好

有什么提示吗

theText.replace(/\d+/g, function(s:String){ return s.split("").reverse().join(""); })

(免责声明:仅测试Javascript,而非ActionScript。)

谢谢@KennyTM!您的解决方案工作完美(经过一些调整)

我只需要指定regexp模式的类型,并删除第3行(:String)中的严格参数类型


也许您应该使用正则表达式来查找字符串的部分(数字),然后执行
stringreverse=newstringbuffer(字符串)。反向()即使阿拉伯语是从右到左写的,数字(1234,而不是£٣٤٤)仍然是从左到右写的。(难道Flash不能处理RTL问题吗?@KennyTM我正在开发一个自定义文本渲染解决方案,它需要翻转数字。太好了!我为Flash做了一点调整(见我的答案),我不明白你为什么要做出改变。。。KennyTM提供的代码应该也适用于AS3。唯一不起作用的是属性中的:字符串。只要把它拿走,你就可以走了。
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