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.



But that doesn't negate does it? Doesn't that look for the match at the
beginning of the text? Also, wouldn't it make more sense to just use '\s'
instead of each individual special character for whitespace?
.



Relevant Pages

  • 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: 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: 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: quick scripting question - finding occurrence in many lines
    ... In the brute force perl solution previously shown, just add whitespace ... to the character class,, which is inserted between every target ... character in the regular expression. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)
  • Re: Simple regexp : s or S
    ... I suspect you're getting confused between ^ used to negate ... a character class, and ^ used to mean "start of string". ... it matches a single whitespace character at the start of the string. ...
    (comp.lang.tcl)