As per this answer, I am making use of a replaceAll()
function to swap arbitrary strings in my javascript (Node) application:
this.replaceAll = function(str1, str2, ignoreCase)
{
return this.replace(new RegExp(str1.replace(/([\/\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g,"\\$&"),(ignoreCase?"gi":"g")),(typeof(str2)=="string")?str2.replace(/\$/g,"$$$$"):str2);
}
I would like to expand this regex, such that it does not try to match anything inside a set of <span>...</span>
tags. (I need to add HTML Span tags around parts of some strings, and I don't want to wrap anything in a span twice, if the patterns would duplicate [I.e., 'Foo' and 'Foobar' in the string "Foobarbaz"])
I am running multiple regex search/replaces on a single string, and I want to make sure that nothing gets processed multiple times.
My understanding is that I'll need a [<SPAN>] ... [</SPAN>]
somehow, but I'm not quite sure on the specifics. Any advice?