mat*_*ndr 7 javascript regex word-boundary
我用这段代码得到了意想不到的结果:
'foo'.match(new RegExp('\bfoo\b')); // Returns null
Run Code Online (Sandbox Code Playgroud)
null当这个返回"foo"时,为什么会返回?
'foo'.match(new RegExp('foo')); // Returns "foo"
Run Code Online (Sandbox Code Playgroud)
单词边界标记是否也与开头和结尾相匹配?
编辑:我需要正则表达式本身是一个字符串因为我注入变量.