perlquestion
jimb
I am trying to write a regex which will validate a string.<br/>
<br/>
<b>The rules:</b><br/>
1) string can contain any character.<br/>
2) string cannot contain a <tt>:</tt> (colon) by itself.<br/>
3) string can contain <tt>::</tt> (two colons) by themselves.<br/>
4) string cannot contain three or more colons by themselves.<br/>
<br/>
<b>Examples:</b><br/>
<tt>
NO sip:userid@example.com<br/>
OK sip::userid@example status::code<br/>
OK ::<br/>
OK ::a::<br/>
NO :::bad_example::
</tt>
<br/>
<br/>
I took the fist two rules and came up with <tt>[^:]+</tt>. So, now the string will fail if there is any colons in it.
<br/>
Rule 3 seems to be a bugger. I tried multiple variations of ::, .*, etc, but no joy.<br>
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.
<br/>
<br/><i>Any help is welcomed.</i>
<br><br>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?<br/>