in reply to regexp golf - homework
i generated a list of random five digit numbers to feed the regex. here's a breakdown of the regex:#!/usr/local/bin/perl -w use strict; $|++; my @numlist; push @numlist, int(rand 100000) for 1..10; for(@numlist) { next if /^$/; /.*?([0-9]).*?\1/ ? print "$_\tmultiple $1\n" : print "$_\tsingle\ +n"; }
*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.Use of uninitialized value in concatenation (.) or string at test_matc +h1.pl line 10. Nested quantifiers before HERE mark in regex m/.*?([0-9]).*?+ << HERE +/ at test_match1.pl line 10.
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: (GOLF) - multiple digit finder regex - 17 chars
by trs80 (Priest) on Feb 02, 2002 at 22:41 UTC | |
|
Re: Re: (GOLF) - multiple digit finder regex - 17 chars
by chipmunk (Parson) on Feb 03, 2002 at 04:21 UTC | |
by particle (Vicar) on Feb 03, 2002 at 04:39 UTC | |
|
Re^2: (GOLF) - multiple digit finder regex - 17 chars
by Anonymous Monk on Dec 11, 2012 at 04:09 UTC |