Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Extraction of letters from a string

by hippo (Bishop)
on Nov 24, 2016 at 13:17 UTC ( [id://1176492]=note: print w/replies, xml ) Need Help??


in reply to Extraction of numbers in an string

I have the following string

A1=<m,n>:<p,q>:<s,t>...go on

I have to extract values m,n,p,q,s,t from the above string. How do i do it?.

You could use m// to match them:

#!/usr/bin/env perl use strictures; my @v = 'A1=<m,n>:<p,q>:<s,t>...go on' =~ /[mnpqst]/g;

Replies are listed 'Best First'.
Re^2: Extraction of letters from a string
by t-rex (Scribe) on Nov 24, 2016 at 13:19 UTC

    here the m,n,p,q... are numbers which can change based on the user, so writing a regex just to hardcode with numbers won't be a good idea i guess

      How was m,n,p etc. supposed to represent digits? Anyway, if you want to match digits, match digits:

      #!/usr/bin/env perl use strictures; my @v = 'A1=<9,8>:<7,6>:<5,4>...go on' =~ /\d/ag;

        Hi, I have one doubt , what should be changed if double or triple digits are to be considered , as of now the above mentioned code (your solution) splits 10 as 1 0

        I edited my post, as i hastily put it, pls check the edited one, thank you that works :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2024-04-23 14:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found