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

Re: String parsing

by Hena (Friar)
on Jan 05, 2004 at 10:57 UTC ( [id://318810]=note: print w/replies, xml ) Need Help??


in reply to String parsing

Well, wouldn't do it with one command. But this should work.
# this is the original string $string=""; # then split on first ':' ($begin,$end)=split (/:/,$string,2); # remember every () separately # this assumes that between () there are no more (), eg not (27(b)) while ($end=~m/\((.+?)\)/g) { push (@result,$1); } # add first unshift (@result,$b); # if wanted to remove () from first # check if need to escape $result[0]=~s/[()]/;
Update: fix typo.

Replies are listed 'Best First'.
Re: Re: String parsing
by bart (Canon) on Jan 05, 2004 at 17:21 UTC
    My solution is in the same realm.
    my($begin, $end) = split /:/, $string, 2; $begin =~ tr/()//d; @result = $begin; push @result, $end =~ m/\((.+?)\)/g;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-03-29 08:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found