in reply to Help with form validation regex

/^..._.*_ear$/s
Or if the fourth character (_) may also be the fourth character from the end:
/^..._(?:.*_)?ear$/s
Or even:
"_" eq substr($_, 3, 1) and "_ear" eq substr $_, -3;

Replies are listed 'Best First'.
Re^2: Help with form validation regex
by John M. Dlugosz (Monsignor) on May 11, 2009 at 18:20 UTC
    Yes, he may have been a bit loose on what he meant by "any char". Maybe he meant word chars, or maybe he meant "any char except an underscore". But, you do show that the simplest answer isn't necessary a regex!
      Thanks everyone!
Re^2: Help with form validation regex
by johngg (Canon) on May 12, 2009 at 13:56 UTC

    In your last code snippet I think the ... "_ear" eq substr $_, -3; is only going to look at the last three characters so the condition will never be true.

    $ perl -le ' $str = q{bit_of_a_pigs_ear}; print q{_ear} eq substr( $str, -3 ) ? q{Match found} : q{No match}; print q{_ear} eq substr( $str, -4 ) ? q{Match found} : q{No match};' No match Match found

    I hope this is of interest.

    Cheers,

    JohnGG