use warnings; use strict; use 5.012; my $data = <<'END_OF_TEXT'; foo bar {{ alpha beta }} baz END_OF_TEXT $data =~ s/ (?: #Non-capturing group {{.*?}} #Text enclosed by double braces \K #Exclude what's to the left of \K from match )? #Match whole group 0 or 1 time \n /\n<br>/gxms; say $data; --output:-- foo <br>bar <br>{{ alpha beta }} <br>baz <br>
It would make more sense to put the newlines after the breaks if you were trying to pretty print some html.
In reply to Re^2: Replace newlines only if not inside braces
by 7stud
in thread Replace newlines only if not inside braces
by jbryan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |