Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: csv'ish string with parens that include commas

by james2vegas (Chaplain)
on Dec 05, 2010 at 03:57 UTC ( #875454=note: print w/ replies, xml ) Need Help??


in reply to csv'ish string with parens that include commas

Use Regexp::Common::list, something like this (presuming your strings and all word characters):

use Regexp::Common 'list'; my $re = qr{ \w+ # word characters (word or function name) (?:\($RE{list}{-pat=>'\w+'}\))? # (optional parameters) }x; my $x = 'joe,sam,x(monkey,lemur)'; my @x = ($x =~ m{$re}g); print join("\n", @x);
returns:
joe sam x(monkey,lemur)


Comment on Re: csv'ish string with parens that include commas
Select or Download Code
Replies are listed 'Best First'.
Re^2: csv'ish string with parens that include commas
by ascetic (Novice) on Dec 05, 2010 at 04:07 UTC

    Thanks. Actually, some of the args will be numbers, but I should be able to take it from here.

    I also looked at using Text::Balanced for a bit, but it seemed like using a hammer to drive a screw.

      \w matches letters, digts and underscore, so that should be sufficient.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://875454]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2015-07-31 06:16 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 (274 votes), past polls