in reply to Re: conditional regex
in thread conditional regex

Your pattern also matches 'YEESS', 'yeeeeeeeeeeeeeeeeeees', and 'YeEeEeEeSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS'.

Probably not what you want.

There's a much simpler solution. Reverse the subject and the pattern:

for my $str (qw[YES YE Y yes ye y YS ES S ys es s YEESS YYYEEs]) { say "$str: ", "yes" =~ /^\Q$str/i ? "ok" : "not ok"; } __END__ YES: ok YE: ok Y: ok yes: ok ye: ok y: ok YS: not ok ES: not ok S: not ok ys: not ok es: not ok s: not ok YEESS: not ok YYYEEs: not ok
Or, instead of the pattern match:
say "ok" unless index "yes", lc $str;

Replies are listed 'Best First'.
Re^3: conditional regex
by BrowserUk (Patriarch) on Aug 22, 2010 at 15:18 UTC

    Indeed that is much simpler. I wish I'd thought of it :)