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

Re: regular expressions - finding repeats

by BronzeWing (Monk)
on Feb 26, 2003 at 21:03 UTC ( #238913=note: print w/replies, xml ) Need Help??

in reply to regular expressions - finding repeats

Well blokhead already posted what's probably the best answer, and the one that I wanted to give, but I've got to post something. So here:

if ($String =~ join('|',map($_ x 5, qw(A B C D E)))) {}

Admittedly it takes 3-4 times as long according to benchmark... but it was so much more fun to write ;p.


Replies are listed 'Best First'.
Re: Re: regular expressions - finding repeats
by ihb (Deacon) on Feb 27, 2003 at 20:45 UTC

    Here's a little attempt to optimize this code. (Not that it's worth optimizing like this since backreferences rule, but anyway... :)) The pattern can be extended to the line below, and as a bonus you get an even uglier expression.   '(?=[A-E])(?:' . join('|',map($_ x 5, qw(A B C D E))) . ')' A side note that actually can be relevant: if you don't rebuild the pattern each time you'll save a lot. And if you use qr// or /o you'll be even happier, usually.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2023-02-02 11:59 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (17 votes). Check out past polls.