I have string like this:
“Some standard text CONST_INSIDE_QUOTES” blah blah CONST “There might be another quotes”
The thing is, that i want to replace all constants in string with some text, but it mustn’t be applied on constants inside text in quotes. I have this regex:
sed “s/([A-Z][A-Z0-9_]*)([^a-z])/<span class=\”const\”>\1<\/span>\2/g”
which of course works for all consts. Any ideas how to exclude its apply on quotes constants? Unfortunately sed only…
Ok, it’s not pretty but it works as long as you don’t have nested quotes.
That is to say:
blah "foo" blah "bar"OK"blah "foo" blah "bar" blah"NOT OKIt uses a the double-quote as the field separator and then only works on odd-numbered fields (via the
%operator) to do its substitutions. This essentially solves the balanced parentheses problem when you don’t have nested quotes.Proof of Concept