perl -i -pe 's/<--BEGIN:(.|\n|\r)*:END-->/stuff/g' file.html
This is so close.
- Now just match with the
/s
modifier, this allows.
to match any char, including newlines. - Most importantly, you want to start the match with
<!--
, note the!
. - Also, you want a non-greedy match like
.*?
, in case you have multipleEND
markers. - Your example input shows that there may be extra spaces.
This would lead to the following substitution:
s/<!--\s*BEGIN:.*?END:\s*-->/stuff/sg
As @plusplus pointed out, the -p
iterates over each line. Let's change Perl's concept of a “line” to “the whole file at once”:
BEGIN { $/ = undef }
or use the -0
command line switch, without a numeric argument.