in reply to prompting a user for input

Here's a neat regex I've learned for Y/N:
/(Y(es)?|N(o)?)/i
this accepts Y, N, Yes, No, and ignores cases.

Replies are listed 'Best First'.
Re: Re: prompting a user for input
by blakem (Monsignor) on Nov 05, 2001 at 02:14 UTC
    You probably want to anchor that at the ends, otherwise 'abcNOdef' and 'blahYblah' will match. Also, the parens around the single char 'o' are unnecessary.
    /^(Y(es)?|No?)$/i

    -Blake

      Looking at:
      ~/^(y|yes)$/i
      This would be my choice:
      ~/^(?:y(?:|es))$/i;
      matches y or yes without any regard to case and doesn't store the match in $1 unnecessarily. TMTOWTDI

      -tengo mas que aprender