Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by Anonymous Monk
on Nov 28, 2001 at 19:40 UTC ( #128065=categorized answer: print w/replies, xml ) Need Help??

Q&A > regular expressions > How can I split on a string except when inside quotes? - Answer 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);

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
NodeReaper lights some incense and reads Tool and Die

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2017-04-30 18:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (542 votes). Check out past polls.