I have this code
htmlString= htmlString.replace( new RegExp( "WW(.+?)WW", "gim" ),
"<span style='color:red;border-bottom:1px dashed red;'>$1</span>" );
This seems to work however it is replacing the www’s in url’s. What I have is WW somestring WW I clip out the text between WW and replace it. However, I can’t seem to only get the exact char sequence. I tried {WW} ^WW [^WW] with the end [$WW] and variations. Also tried \bWW string \bWW and no match.
Any help would be great, thanks.
Assuming that there is something else than alphanumeric characters after the starting
WWand before the endingWW(whitespace, for example), then you could do this:Using a regex object instead of a string literal makes it easier to read. If you had used
\bin a string literal it would have meant “backspace” – you need to escape backslashes in a string literal, so the above regex would become"\\bWW\\b\\s*(.+?)\\s*\\bWW\\b".