a 123 456 789 b 123 456 789 c 123 456 789 d 123 456 789 <p>e 123 456 789 f 123 456 789</p> <p>e 123 456 789 f 123 456 789 g 123 456 789 h 123 456 789</p> <p>1 123 456 789 2 123 456 789 3 123 456 789 4 123 456 789</p>
The following matches the last three paragraphs:
perl -p0e 's/(<p>(?:(?!<\/p>).)*<\/p>)/-->$1<--/migs' example.txt
You want to change the regex, to match the third paragraph only, because it contains an empty line.
Hint: the following does not work
perl -p0e 's/(<p>(?:(?!((<\/p>|\n\n))).)*<\/p>)/-->$1<--/migs' example.txt
In reply to regex exercise by Cilice
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |