A colleague asked me about the problem of regular expression, and I can not find and answer for it.
We use borders to highlight specific lengths of text in a text editor, but here is an example of code that shows the problem:
<script type="text/javascript"> var str = "Alpha , Beta, Gamma Delta Epsilon, AAlphaa, Beta Alpha<br/>"; var rx = new RegExp('\bAlpha\b','gim'); document.write(str.replace(/\b(Alpha)\b/gim, '-- $1 --')); document.write(str.replace(rx, '== $1 ==')); </script>
The problem is that the first literal str.replace works, but the RegExp parameter does not work.
I have the same behavior in IE and FF, does anyone know why?
javascript regex word-boundary
Russ Clarke
source share