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

Re: regex to split on ' ', but skip spaces inside quotes

by duff (Vicar)
on Sep 21, 2007 at 21:10 UTC ( #640440=note: print w/replies, xml ) Need Help??


in reply to regex to split on ' ', but skip spaces inside quotes

Rather than thinking in terms of "splitting on spaces", may be it would work better if you thought in terms of "gather the things I want". For instance, would this work for you:

#!/usr/bin/perl use strict; use warnings; my $string = q(hi my name is 'john doe'); my @parts = $string =~ /'.*?'|\S+/g; print map { "$_\n" } @parts; __END__
?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://640440]
help
Chatterbox?
[Happy-the-monk]: even more OT: received the complete series of Robin Hood/Robin of Sherwood 1984 on used dvds this morning :)
[Happy-the-monk]: (purely coincidental)
[jkva]: Corion Hey there :)
[Happy-the-monk]: Discipulus: are there any perl monks in Milano?
[Discipulus]: i the moment likely no
[karlgoethebier]: i wonder now it will be with my glasses.
[Discipulus]: Milan Perl Mongers seems frozen at 2009
[Discipulus]: karl you dont shoot with eyes, you shoot with the soul
[jkva]: Reminds me of Guardians of the Galaxy

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2017-10-20 10:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (260 votes). Check out past polls.

    Notices?