I need to replace parts of the text, but only if its substrings are not enclosed between '<' and '>'.
For example, if I have the following text
<text color='blue'>My jeans are red</text> <text color='red'>I am wearing a red t-shirt</text> <text color='yellow'>I like red fruits</text>
and I want to replace the word βredβ with another word, how can I replace a word in this text without replacing the words contained between β<β and '>'? I tried to write a regex for this, but I failed ...
The dumb way that I thought is to parse all the text (char to char), see if I'm inside or outside <...> and replace the appearance of the text only if I'm outside ... I think that There must be a smarter way!
source share