Replacing a target pattern everywhere except inside specific chunks, can be achieved with a regex of the following form:
s/((?:CHUNK_TO_BE_EXCLUDED|.)*?)TARGET/$1REPLACEMENT/gs
In your example, TARGET would be \n and REPLACEMENT would be \n<br>. The CHUNK_TO_BE_EXCLUDED pattern would have to match a whole block wrapped in double braces. You can use {{.*?}}\n, unless brackets can be nested and you need to guarantee that you match properly balanced pairs, in which case you can find a howto for constructing the pattern you need in perlfaq6.
In reply to Re: Replace newlines only if not inside braces
by smls
in thread Replace newlines only if not inside braces
by jbryan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |