http://www.perlmonks.org?node_id=27851


in reply to Another for those who love the Regular Expression questions...

For the record, I know this won't catch escaped quotes, but.. it solves the problem at hand.

I did this just to show that a quick hack is possible, even in a one liner... I love map.

my $string = q|Are "Perl Monks" required to swear an "Oath of Celibacy +?"|; my @broken = map { /"([^"]+)"/ ? $1 : split } split /\s?([^"]+")\s?/, + $string; print "[$_] $broken[$_]\n" foreach 0 .. $#broken;
Enjoy!
--
Casey
  • Comment on Re: Another for those who love the Regular Expression questions...
  • Download Code

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.