This really has me puzzled. Say I have a files that may have the occurance of "one\ntwo" within:
echo -e 'zero\none\ntwo\n\n three' zero one two three
I want to recurse through the files, and if they contain the block "one\ntwo", I want to put identifiers around it, and a prescribed number of newlines, regardless of how many there were before:
echo -e 'zero\none\ntwo\n\n three' | perl -0777 -pe 's{\s*(one\ntwo +)\s*}{\n\n<begin block>\n\n$1\n\n<end block>\n\n}' zero <begin block> one two <end block> three
Great - but I want to preserve the offset of the first word on the rest of the text that follows. So I think, no problem, I'll just do this:
echo -e 'zero\none\ntwo\n\n three' | perl -0777 -pe 's{\s*(one\ntwo +)\s*?( *)}{\n\n<begin block>\n\n$1\n\n<end block>\n\n$2}' zero <begin block> one two <end block> three
It preserves the indent, but now I have additional newlines after <end block>. Where did they come from? The second capture is only capturing spaces, so how did two extra \n's get inserted?
In reply to matching and mysterious captures by Allasso
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |