regex not working "within" javascript string
Posted
by
Tim
on Stack Overflow
See other posts from Stack Overflow
or by Tim
Published on 2011-11-19T09:46:13Z
Indexed on
2011/11/19
9:50 UTC
Read the original article
Hit count: 231
I'm trying to replace all mentions of [b] in a text string and replace it with <b>
. The problem with what I'm using below this that it's replace every [b] on the page, and I only want it to change the [b]'s within the text string ("text") that I'm sending in.
Taking out the 'g' for global in the regex doesn't work very well because it then doesn't replace them all...
text = text.replace(new RegExp('(^|\\s|>)\\[b](\\S.*?\\S)\\[/b]($|\\s|<)', 'gim') , '$1<strong>$2</strong>$3');
any ideas? Thanks
© Stack Overflow or respective owner