Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Extraction of numbers in an string

by johngg (Canon)
on Nov 24, 2016 at 14:14 UTC ( [id://1176498]=note: print w/replies, xml ) Need Help??


in reply to Extraction of numbers in an string

You could split into pairs on a '<' or a '>' optionally followed by ':<' then split the pairs on a comma.

johngg@shiraz:~/perl/Monks > perl -Mstrict -Mwarnings -E ' my $str = q{<1,2>:<5,7>:<3,0>}; my @nos = map { split m{,} } split m{(?x) < | > (?: :< )?}, $str; say for @nos;' 1 2 5 7 3 0

I hope this is helpful.

Update: Changed quantifier from * to ?.

Cheers,

JohnGG

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-19 19:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found