且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

新的Regexp不起作用

更新时间:2023-12-04 14:02:10

你应该改用它......

You should use this instead...

new RegExp("\\btest[a-z]*", "g");

...如 \b 将当JavaScript解析器通过相应的字符串文字工作时,可以插入到(无斜线)字符中。解决方案是逃避斜线本身。

... as \b will be interpolated into a single (slashless) character when JavaScript parser works through the corresponding string literal. The solution is to escape slash itself.

DEMO: http://jsfiddle.net/HDWBZ/1/