in reply to [SOLVED] Regex : Limit value of a string

Imho your if solution is the best readable.

Hence better stick with it!

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^2: Regex : Limit value of a string
by locked_user sundialsvc4 (Abbot) on Oct 14, 2015 at 12:40 UTC

    Wholeheartedly agree.   And here, to me, is why:   a regex pattern should match what the string looks like, and to extract pieces from it, whereas if/then logic should then be used to test for what those pieces contain.   Now, obviously, there are cases where certain digits of a string are known to serve only as identifiers of the string itself ... e.g. the leading digits of ISBNs for books ... but this is not such a case.   Someday it is quite likely that someone will want to change this logic, say to allow a different number to be in this position, or to allow more than one, or to add some other ruling constraint.   If you are doing this in the regex, you’re making a mess for that person.   :-)