in reply to Re: Determing if this regex matched
in thread Determing if this regex matched
Hey! I had no idea s/// returned anything. Also a more straightforward way to write the regex. Problem is, with the or, the second sub doesn't get executed if the first one matches, so there is still the trailing quote on examples 1 and 4. I suppose one could do
But that doesn't seem very elegant.my @items = ('"Title Text Example"', 'Title Text Example', ' Title Tex +t Example ',' "Title Text Example"'); foreach my $title (@items) { my $changed = 0; if ($title =~ s/^[\s"]+//) { $changed=1; } if ($title =~ s/[\s"]+$//) { $changed=1; } if ($changed) { print "$title\n"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Determing if this regex matched
by ww (Archbishop) on Aug 06, 2011 at 20:06 UTC | |
by cormanaz (Deacon) on Aug 06, 2011 at 20:34 UTC | |
by AnomalousMonk (Archbishop) on Aug 07, 2011 at 10:22 UTC | |
Re^3: Determing if this regex matched
by merlyn (Sage) on Aug 06, 2011 at 20:12 UTC | |
by cormanaz (Deacon) on Aug 06, 2011 at 20:30 UTC |
In Section
Seekers of Perl Wisdom