in reply to Trying to find all items in between quotation and speech marks
Put your quotes outside you parentheses, so only the string gets stored in $1. I'd also change from a *? to a +?, since you likely aren't interested in null strings. One case you should consider which is currently not handled, is "I like Perl," said Mary, "since it gives me more time with my lamb!" - you'll match on ' said Mary, ' in addition to what you want.
while (my $text = <DATA>) { if ($text =~ /['"](.+?)['"]/ ){ print "Found $1 \n"; } else { print "Out of luck \n"; } }
Update: Details on regular expressions can be found in the documentation in Perl regular expressions, quick reference guide, and tutorial.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Trying to find all items in between quotation and speech marks
by Anonymous Monk on Jan 23, 2009 at 19:29 UTC |