I guess you meant "should NOT match < between the double quotes". In this case, a lookahead does the trick:
s = '<b>"ABC<DEF" match<this "ignore<this" end'
s.replace(/<(?=("[^"]*"|[^"]+)+$)/g, "@")
// "@b>"ABC<DEF" match@this "ignore<this" end"
Frage
I need a regular expression to check if a character doesn't appear in double quotes("). For example, if i have something like <b>"ABC<DEF"</b>
, then the regular expression should match <
of both the tags and it should not match <
between the double quotes.
Lösung
I guess you meant "should NOT match < between the double quotes". In this case, a lookahead does the trick:
s = '<b>"ABC<DEF" match<this "ignore<this" end'
s.replace(/<(?=("[^"]*"|[^"]+)+$)/g, "@")
// "@b>"ABC<DEF" match@this "ignore<this" end"