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

Re: Regex fun

by moritz (Cardinal)
on Dec 15, 2009 at 14:28 UTC ( [id://812878]=note: print w/replies, xml ) Need Help??


in reply to Regex fun

which unfortunately does't do anything. I'd like to know why?
Three things are wrong: First of all there's no digit in you input, so [0-9] can't match. Secondly you don't capture the result from [0-9]+, so matching against \1 is bound to fail. Thirdly you can't use a capture as a quantifier, as you already guessed.

Update: Just found that there are actually some 1s in the input. If all sequences are short, you can just generate them:

my $re = join '|', map { qr/\+$_[ACGTNacgtn]{$_}/} 1..20; s/$re//g;

Should still be fairly efficient, especially with perl-5.10, which optimizes regex alternations with constant prefixes.

Second update: Added a missing \+ JadeNB++ for noticing.

Perl 6 - links to (nearly) everything that is Perl 6.

Log In?
Username:
Password:

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

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

    No recent polls found