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.

有帮助吗?

解决方案

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"
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top