« Comfy Chair - Floating Harbour, Bristol | Main | When an array is not an array »
April 16, 2008
Regular expression for 6 digits OR 25 digits
I can write a regular expression to match ANY number of digits between 6 and 25 ...
^[[:digit:]]{6,25}$
but how would I write a regular expression to match either 6 digits or 25 digits, but no number in between?
^([[:digit:]]{6}|[[:digit:]]{25})$
(The regular expressions in this example are Tcl and PHP/ereg types. use \d instead of [[:digit:]] for PHP/preg and Perl.)
You may wonder why I want this. A client with 6 digit or 25 digit part numbers, a year number that can be 2 or 4 digits ...
Posted by gje at April 16, 2008 07:06 PM