Do you know where your variables are? | |
PerlMonks |
Regex Validationby jimb (Novice) |
on Jul 30, 2009 at 00:13 UTC ( [id://784425]=perlquestion: print w/replies, xml ) | 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. The rules: 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. Examples: NO sip:userid@example.com OK sip::userid@example status::code OK :: OK ::a:: NO :::bad_example:: 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?  
Back to
Seekers of Perl Wisdom
|
|