I am totally new to regex and I just can't get it to work. I have this Javascript code
html.replace(new RegExp(util.escapeRegex(key), 'g'), 'something');
But I would only like it to fire if util.escapeRegex(key)
is outside from quotes "/'
Note that key
is something like :key:
Assuming no double quote is unbalanced, this should do the trick for you.
html.replace(new RegExp(util.escapeRegex(key) + '(?=(?:(?:[^"]*"){2})*[^"]*$)', 'g'), 'something');