Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

( #128065=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 Anonymous Monk

This doesn't handle all the subtle things (backslashes, single-quotes, etc) that Text::ParseWords does, but it works for the simple cases, and produces your expected output exactly (quotes intact): my @items = ($string =~ /(".*?"|\S+)/g);

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 exploiting the Monastery: (6)
As of 2015-07-04 08:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (58 votes), past polls