开发者

Javascript RegExp with tagged expressions

I would like to know if there is a way to perform replacement with regular expressions in JS using tagged expressions, like scintilla engine does (used in Notepad++, for example). For instance, to replace numbers with a colon as decimal separator by a dot, you may use the following expressions in Notepad++:

regexp开发者_JAVA技巧: /([0-9]+),([0-9]{2})/ replace: \1.\2

Could I do something like this in JS?

Regards José


Yes.

str = str.replace(/([0-9]+),([0-9]{2})/, '$1.$2');


You sure can!

"My test string with a 56,35% chance of success".replace(/([0-9]+),([0-9]{2})/gi, "$1.$2");


Use replace. Good documentation here:

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/replace

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜