Вопрос

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