in reply to Re^2: Tweak for my Perl Regex that screens for digits only
in thread Tweak for my Perl Regex that screens for digits only
Update: My test case is as follows:
use strict; use warnings; my @strings; $strings[0] = "44 (1234) 123398 Ext 123"; $strings[1] = "+44 (1234) 123398 Ext 123"; $strings[2] = "44 (1234) 123398 Ext 123 xxxxxxxxxxxxxxx"; $strings[3] ="416-967-1111 ext. 123 xxxxxxxxxxxxxxxxx"; my $counter=0; for my $string (@strings) { if ($string =~/^(?:Ext|\d|\)|\(|\.|\s|\+|\-)+$/i) { print "$counter good\n"; } $counter++; }
Which returns:
0 good
It fails to match with a leading +, which I haven't got to the bottom of yet, but rejects all the wrong strings. (I'd missed out a vital |, which stopped the + matching - thanks to ysth for spotting it).
--------------------------------------------------------------
"If there is such a phenomenon as absolute evil, it consists in treating another human being as a thing."
John Brunner, "The Shockwave Rider".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Tweak for my Perl Regex that screens for digits only
by ysth (Canon) on Jan 26, 2006 at 11:33 UTC | |
|
Re^4: Tweak for my Perl Regex that screens for digits only
by hackermike (Novice) on Jan 25, 2006 at 19:50 UTC |