in reply to Help with form validation regex

How about:

#!/usr/bin/perl while(<DATA>) { chomp; if( /\A[\w]{3}_\w+_ear\Z/ ) { print "$_ matches \n"; } else { print "no joy for $_ \n"; } } __DATA__ ab_wehave_noear abc_test_ear abc_test_two_ear abcc_test_ear
which prints:
no joy for ab_wehave_noear abc_test_ear matches abc_test_two_ear matches no joy for abcc_test_ear
I realize your problem definition said "characters" not "word thingies". I'm confident you can munge it to match your expected input range.


Be Appropriate && Follow Your Curiosity

Replies are listed 'Best First'.
Re^2: Help with form validation regex
by JavaFan (Canon) on May 11, 2009 at 19:11 UTC
    I wonder why you write: [\w]{3} instead of \w{3}.

      So do I. The probable thought stream was an intent to specify more than \w and then discarding the idea without discarding the [].

      Bad Michael, no XP today.


      Be Appropriate && Follow Your Curiosity