[英]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). 我想知道是否有一种方法可以像使用scintilla引擎一样(例如在Notepad ++中使用),使用标记表达式在JS中用正则表达式执行替换。 For instance, to replace numbers with a colon as decimal separator by a dot, you may use the following expressions in Notepad++: 例如,要将数字用小数点分隔的冒号作为冒号,可以在Notepad ++中使用以下表达式:
regexp: /([0-9]+),([0-9]{2})/
replace: \\1.\\2
regexp: /([0-9]+),([0-9]{2})/
替换: \\1.\\2
Could I do something like this in JS? 我可以在JS中做类似的事情吗?
Regards José 问候何塞
是。
str = str.replace(/([0-9]+),([0-9]{2})/, '$1.$2');
你当然可以!
"My test string with a 56,35% chance of success".replace(/([0-9]+),([0-9]{2})/gi, "$1.$2");
Use replace
. 使用replace
。 Good documentation here: 好的文档在这里:
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/replace https://developer.mozilla.org/zh-CN/JavaScript/Reference/Global_Objects/String/replace
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.