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;