in reply to Re: Regular expression for hexadecimal number
in thread Regular expression for hexadecimal number
Sure you could; the more important question is should you. You're probably better off implementing a "lower level" check (is this a 4 digit number) at the regex level and then using comparisons in code to check range membership.
What you want to be worried about is when your requirements shift and now you've got to check if it's between 3021 and 5123 for the comparisons-in-code version it's just a matter of changing two numbers (or redefining FOO_RANGE_MIN and FOO_RANGE_MAX constants since one would never use magic numbers inline, of course :) rather than coming up with a new clever regex to match the new rage.
Update: Just to show it can be done (but again, probably shouldn't): /^ 3 (?: 0 [1-9] \d | [1-9] \d \d ) | 4 (?: 0 \d \d | 1 (?: [01] \d | 2 [0123] ) ) $/x
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Regular expression for hexadecimal number
by mjscott2702 (Pilgrim) on Jul 30, 2007 at 14:31 UTC |