in reply to conditional regex

for a simple question I would prefer a simple solution (maybe not so perfect but easy to understand also to non-regexperts). This does exactly "match y or yes in case-insensitive manner":

while(<>) { print "yes\n" if /(y|yes)/i; }

update: above will match everything with a 'y' inside as ikegami observed. Below code does what I meant (this time tested before posting)

foreach (qw( YES YE Y yes ye y ys es s e Yeeessseeseeesssssess)){ print "$_ = yes\n" if /^(y|yes)$/i; }

Replies are listed 'Best First'.
Re^2: conditional regex
by ikegami (Patriarch) on Aug 23, 2010 at 03:31 UTC
    Try typing "fluffy"

      I guess you don't mean I should use a ball of cotton ...

      what do you mean with typing "fluffy" ?

        Try running the code you suggested and entering "fluffy" (or "young" or "cyan").