Why do these 2 regular expressions not behave the same?

后端 未结 1 658
-上瘾入骨i
-上瘾入骨i 2021-01-21 02:04

I am attempting to create a regular expression with the constructor syntax like this new RegExp(\'\\bword\\b\', \'g\'), but it does not behave as expected. Rather i

相关标签:
1条回答
  • 2021-01-21 02:33

    For a string \b means backspace.

    For a regex \b means word-boundary.

    To make sure the regex version is used, add an extra backslash \ before each backslash in the string to escape the escape characters.

    0 讨论(0)
提交回复
热议问题