Wow. Just when you thought you knew everything about regular expressions, you find out a bunch of stuff you never knew!
Thanks Jeff. I hope you're getting credit somewhere for all the help you give on this list, you deserve it. - Bryan > On Oct 19, Bryan Harris said: > >> Does anyone happen to know why this doesn't work as expected? >> >> perl -e '$_="1\n";s/\Z/2/g;print' >> >> Why does it print "2" twice? > > It works as *I* expect it to. \Z matches at the end of the string, OR > before a NEWLINE at the end of the string. Therefore, in the string > "japhy", \Z matches after the 'y', and in the string "japhy\n", \z matches > after the 'y' and after the '\n'. > > Perhaps you want \z, which only matches the end of the string. If you > want to match at the end of the string, and ignore a final \n, then I > suggest you do: > > s/\Z(?<!\n)/2/g; > > That will match \Z, but not if it is AFTER a newline. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>