in reply to How to slice complicated string into an array
I think I like the Text::CSV or Text::ParseWords module-based parsing approaches a bit better, but if you have Perl version 5.10+, you can use a regex approach that's almost identical to your OPed regex if you take advantage of the (?|...|...) "branch reset" construct (see Extended Patterns in perlre):
(Note that what appears above as \"([^^\x22]*)\" due to the peculiarities of Windose command line interpretation and the limitations of my personal REPL should really be "([^\x22]*)" or better yet "([^"]*)")c:\@Work\Perl\monks>perl -wMstrict -le "use 5.010; ;; use Data::Dump qw(dd); ;; my $s = '\"word1\",word2,\"word3,word4\"'; ;; my @ra = $s =~ m{ (?| \"([^^\x22]*)\" | ([^,]+) ) (?:,|$) }xmsg; dd \@ra; " ["word1", "word2", "word3,word4"]
Give a man a fish: <%-{-{-{-<
|
|---|