Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: (GOLF) - multiple digit finder regex - 17 charsby particle (Vicar) |
on Feb 02, 2002 at 21:38 UTC ( [id://142965]=note: print w/replies, xml ) | Need Help?? |
it's not as difficult as you may think. the regex looks like this: /.*?([0-9]).*?\1/. including the brackets, it's 17 characters long! here's the full program:
i generated a list of random five digit numbers to feed the regex. here's a breakdown of the regex: .*? i match zero or more characters, non-greedily ([0..9]) match numbers 0..9, save in \1 .*? again match zero or more characters, non-greedily \1 find the next instance of the character in \1 * *what's most interesting about this, is that $1 does not work in place of \1. instead, on my perl 5.6.1 install, it warns with: by the way, there's nothing to stop this from working with letters, as well. just change 0..9 and you're on your set. enjoy! Update: i see the error of my ways. tilly's right (below). i solved the exact opposite of the problem, which was pretty easy! whoops!
~Particle
In Section
Seekers of Perl Wisdom
|
|