in reply to Regex Validation

The magic you need is to look around. Consider:

use strict; use warnings; my @tests = ( 'sip:userid@example.com', 'sip::userid@example status::code', '::', '::a::', ':::bad_example::', ); print /^([^:]|(?<!:)::(?!:))+$/ ? "OK $_\n" : "NO $_\n" for @tests;

BTW, the flack you got was for not (obviously) showing what you had tried. Although you did actually show [^:]+, because you didn't bother with code tags the square brackets turned the ^: into a link. There is a strong requirement here for supplicants to demonstrate that they have actually had a go at solving the problem themselves by showing the code they have tried.


True laziness is hard work

Replies are listed 'Best First'.
Re^2: Regex Validation
by AnomalousMonk (Archbishop) on Jul 30, 2009 at 03:18 UTC
    My thought was "the same, but backwards": since everything seems OK except a group of either one or three or more colons (delimited by non-colons), look for that pattern and reject if found.
    >perl -wMstrict -le "my $invalid = qr{ (?<! :) (?: : | :{3,}) (?! :) }xms; print '------ output ------'; for my $s (@ARGV) { print $s =~ $invalid ? 'NO' : 'OK', qq{ '$s'}; } " "sip:userid@example.com" "sip::userid@example status::code" "::" "::a::" ":::bad_example::" ":" ":::" "::::" ------ output ------ NO 'sip:userid@example.com' OK 'sip::userid@example status::code' OK '::' OK '::a::' NO ':::bad_example::' NO ':' NO ':::' NO '::::'