in reply to Re: match lines containing state abbreviationin thread match lines containing state abbreviation
Splitting the lines to create an array is probably what I would have done. However, if you want to work directly with a multiline string, here's one way to do it:
$ perl -Mstrict -Mwarnings -E '
my $lines = "AZ\nSX\nAZ\nDC\nAB\nYZ\n";
$lines =~ s/(?>[^A].|.[^Z])\n//gm;
In my opinion, the multiline solution is a lot more cryptic than the array solution.
.desrever si txet eritne ehT
.backwards are (letters the not but) words the Only
ehT sdrow era ni redro, tub eht srettel era eht rehto yaw.
Who ndees baacdkrws wehn you have Tceilmopgyya?
?wdors reeersvd up meixd about How
.tusnnmihep rof nuttolg a m'I
Results (441 votes). Check out past polls.