Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Find Number in String then Ignore Characters proceeding

by aaron_baugher (Curate)
on May 29, 2012 at 21:33 UTC ( [id://973133]=note: print w/replies, xml ) Need Help??


in reply to Find Number in String then Ignore Characters proceeding

If you know that the characters in question will always be uppercase letters (or some other particular character set that doesn't include the next + or -), it's fairly easy: capture the digits and letters that follow a + or -, and use substr to drop the correct number of letters off the beginning:

#!/usr/bin/env perl use Modern::Perl; my $str = ".,a..A,,C..+4ACGTG.,-2TG,,...,a"; $str =~ s/[+-](\d+)(\w+)/substr $2, $1/ge; say $str;

Aaron B.
Available for small or large Perl jobs; see my home node.

Log In?
Username:
Password:

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

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

    No recent polls found