dwhite20899 has asked for the wisdom of the Perl Monks concerning the following question:
I've been using this code and regex as the heart of an is_MD5 subroutine:
if ($hash =~ /[0-9a-f]{32}/i) { return(1); }
Now I'd like to generalize it for other hex hash strings, and I think I've negated it correctly like so:
if ($hash =~ /[^0-9a-fA-F]/ ) { return(0); }
The new code continues into some other checks as long as the entire hash string is good hex. It works with all my test cases, but I don't have a large enough set to find any performance difference. Am I doing something stupid that could bite me down the road?
Update: Kyle, thanks, it was couched in other checks, but the more atomic the better, IMO. Davidrw, THANKS! I've seen that but forgot about it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: hex-only regex
by davidrw (Prior) on Jan 17, 2007 at 16:55 UTC | |
|
Re: hex-only regex
by kyle (Abbot) on Jan 17, 2007 at 16:16 UTC | |
by merlyn (Sage) on Jan 17, 2007 at 16:44 UTC | |
by jettero (Monsignor) on Jan 17, 2007 at 19:18 UTC | |
by Roy Johnson (Monsignor) on Jan 17, 2007 at 23:46 UTC | |
|
Re: hex-only regex
by Joost (Canon) on Jan 17, 2007 at 15:38 UTC | |
|
Re: hex-only regex
by fenLisesi (Priest) on Jan 18, 2007 at 11:24 UTC |