[thelist] regex: 0-1 range VS optional

Matt Warden mwarden at gmail.com
Thu Feb 15 12:45:49 CST 2007


On 2/15/07, Brian Cummiskey <brian at hondaswap.com> wrote:
> normal:  123456  (1 to 7 digits in length)
> drop ship:  D123456 (gets a D prefix)
> child item:  123456A (gets a single letter suffix)
> and there can also be drop ship child items, as in D123456A
>
> I've come up with two versions which both appear to negate bad entries
> correctly, but i'm not sure which is considered more proper:
>
> ^(d|D)?[0-9]{1,7}([a-zA-Z]{0,1})$
> ^(d|D)?[0-9]{1,7}([a-zA-Z]?){1}$
>
> the first allows either 0 or 1 letters at the end, where as the second
> allows 1 letter, optionally.

As far as I can tell, these are equivalent. The way I'd format it:

^[dD]?[0-9]{1,7}[a-zA-Z]?$

But, is "0" really a valid part number?

-- 
Matt Warden
Cleveland, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.



More information about the thelist mailing list