Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Answer: How can I split on a string except when inside quotes?

( #235536=categorized answer: print w/ replies, xml ) Need Help??

Q&A > regular expressions > How can I split on a string except when inside quotes? contributed by Coruscate

Late entry: how about something like this:

my $string = 'first-item "second item" ' . 'third-item "fourth item"'; my %items; push @{$items{ $1 =~ /"/ ? 'quoted' : 'unquoted' }}, $1 while $string =~ /(".*?"|\S+)/g; print 'Quoted: ', join(', ', @{$items{'quoted'}}), "\n"; print 'Unquoted: ', join(', ', @{$items{'unquoted'}}), "\n";

Comment on Answer: How can I split on a string except when inside quotes?
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2015-04-27 21:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who makes your decisions?







    Results (511 votes), past polls