Re: Negate a regular expression



On Fri, Dec 29, 2006 at 11:36:25PM -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;

Will that do what I want?

If you want anything but a given pattern, the best way to do it is
usually by using the !~ operator. Thus, if you have a pattern $foo,
this matches that pattern:

exit if $ans =~ m/$foo/i;

.. . . while this matches anything but that pattern:

exit if $ans !~ m/$foo/i;

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
"A script is what you give the actors. A program
is what you give the audience." - Larry Wall
.



Relevant Pages

  • Re: remove several lines from a file
    ... where the lines have a pattern ... Perl isn't a toolbox, but a small machine shop where you can special-order ... certain sorts of tools at low cost and in short order. ... -- Larry Wall ...
    (comp.unix.shell)
  • Re: How does a "script" differ from a "program" or "subroutine"?
    ... Larry Wall said it best: ... "A script is what you give the actors, a program is what you give the ...
    (comp.lang.python)
  • Re: export script problem
    ... "A script is what you give the actors. ... is what you give the audience." ... - Larry Wall ...
    (perl.beginners)
  • Re: Non jugglers
    ... I do like the fact that it reminds the audience that the pattern doesn't ... I don't think the audience needs nor wants to know how difficult. ... I think holsters for juggling have already been done, in a cowboy western ...
    (rec.juggling)
  • Re: What type of microphone should I use?
    ... As part of a stage show, the audience would interact by shouting out ... compare it to the waveform guide pattern. ...
    (rec.audio.pro)