Re: Negate a regular expression




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;

Will that do what I want?

nope. you need to re-read the section on character classes...

anyway, change the sense of the test:

exit unless $ans =~ m{^ y(es)? $}xi;

or, to answer your original question:

exit if $ans !~ m{^ y(es)? $}xi;

-jp

.



Relevant Pages

  • Re: Need some help with Exit Event
    ... You would have to hive it off somewhere, like a hidden worksheet or a text ... If ans = vbYes ... (remove nothere from the email address if mailing direct) ... > would save and if no would exit the entire application. ...
    (microsoft.public.excel.programming)
  • Re: Why is this not working?
    ... Mathew Snyder wrote: ... foreach my $email { ... but a small machine shop where you can special-order ...
    (perl.beginners)
  • Re: Exit status or function return value?
    ... function calc, which must be 0. ... The "return $ans" command sets the function's exit status to $ans. ... echo "Function cal requires atleast three args" ...
    (comp.unix.shell)
  • Re: The Promise of Forth
    ... ANS Forth and won't work on all systems, ... have aptly-named words that execute EXIT to bail out from the ... IF EXIT THEN ... ... POSTPONE 0= POSTPONE IF POSTPONE EXIT POSTPONE THEN; ...
    (comp.lang.forth)
  • Re: class object using widget
    ... # get widget classes from tkMessageBox ... def quit: ... ans = askokcancel('Verify exit', ... "Really quit?") if ans: Frame.quit ...
    (comp.lang.python)