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 = $("#input").val();
text = text.replace(new RegExp('(^|\\s|>)\\[b](\\S.*?\\S)\\[/b]($|\\s|<)', 'gim') , '$1<strong>$2</strong>$3');
any ideas? Thanks
text = text.replace(/(^|\s|>)\[b\](.*?)\[\/b\]($|\s|<)/gim, '$1<strong>$2</strong>$3');textvariable, so if that variable holds the whole page obviously it'll do replacements within the whole page. How do you settextbefore doing the replace?textvariable in the local scope.