|Pathologically Eclectic Rubbish Lister|
Regex Validationby jimb (Novice)
|on Jul 30, 2009 at 00:13 UTC||Need Help??|
jimb has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to write a regex which will validate a string.
1) string can contain any character.
2) string cannot contain a : (colon) by itself.
3) string can contain :: (two colons) by themselves.
4) string cannot contain three or more colons by themselves.
OK sip::userid@example status::code
I took the fist two rules and came up with ^:+. So, now the string will fail if there is any colons in it.
Rule 3 seems to be a bugger. I tried multiple variations of ::, .*, etc, but no joy.
My next steps will be passing over the string twice (once with rules 1 and 2, and once with rule 3) and if it works, I'll try rule 4.
Any help is welcomed.
P.S. I am not sure if there is a problem with moochers around here, but does asking for 'any help' mean that I want someone to write the code for me?