Re: Negate a regular expression



Ken Foskey wrote:
On Fri, 2006-12-29 at 23:36 -0500, Mathew Snyder wrote:
I'm trying to set up an if clause to exit if an answer given is anything but
either any case combination of 'y' or 'yes'. This is what I have:

exit if $ans =~ m/[^y|^yes]/i;


exit if $ans =~ m/^(y|yes)[ \t\r\n]*$/i;

The brackets are a group, square brackets are a character class. It is
probably a good idea to ignore whitespace around the error as well.



Let me clarify though.

I have a script that will grab a bunch of emails which need to be deleted from a
database and displays them. I then want it to ask if the user wishes to delete
them. I want 'No' to be the default so that anything other than any case
combination of 'y' or 'yes' will cause the script to exit. This includes simply
hitting 'enter' or entering anything that ISN'T 'y' or 'yes', case
notwithstanding. So having the regex look also for whitespace characters will
defeat this goal.

So how do I negate this if classes aren't the proper way to go?

Mathew
.



Relevant Pages

  • Re: Negate a regular expression
    ... square brackets are a character class. ... combination of 'y' or 'yes' will cause the script to exit. ... So having the regex look also for whitespace characters will ...
    (perl.beginners)
  • Re: Copying files from One PC to another.
    ... > Here is my script - it works, but I suspect there should be a better way ... > use strict; ... > All pointers will be appreciated. ... characters that are not included in the \w character class. ...
    (perl.beginners)
  • Re: Negate a regular expression
    ... Ken Foskey wrote: ... square brackets are a character class. ... probably a good idea to ignore whitespace around the error as well. ...
    (perl.beginners)
  • Re: Negate a regular expression
    ... Ken Foskey wrote: ... square brackets are a character class. ... I put that first and the exit statement in the else clause and it does ...
    (perl.beginners)
  • Re: Square Brackets
    ... Square brackets when needed. ... PRIMARY which in this is context is a an identifier and not a keyword. ... ON in a CREATE TABLE script. ... Roy Harvey ...
    (microsoft.public.sqlserver.tools)