Re: Negate a regular expression



Chad Perrin wrote:
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;


Thanks. That looks like exactly what I was looking for.

Mathew
.



Relevant Pages

  • Re: perl file parsing
    ... AGGACATGCGGCCCGGCGACCTCATCATCTACTTCGACGACGCCAGCCACGTCGGGATG ... the number of times the pattern has occured. ... chomp; #remove newline characters ...
    (perl.beginners)
  • Re: Calculate Last Digits
    ... This might work faster by adding the following line at this point: ... Exit For, as discussed at enormous length in older threads, but this is ... I did get a big boost by switching from strings to longs for the pattern ...
    (microsoft.public.vb.general.discussion)
  • Re: regexp (vim6)
    ... pattern would match Function, unless preceeded by Exit or End - which is ... Exit or End, followed by Function. ... Prev by Date: ...
    (comp.editors)
  • what are the USERID,PASSWD in /etc/passwd
    ... echo "Usage: `basename $0` USERNAME" ... exit $E_WRONGARGS ... file_excerpt $pattern ...
    (comp.unix.shell)
  • Re: perl file parsing
    ... my $fastaFile = 'myfile'; ... my $pattern = 'CTTGGCGAGAAGGGCCGCTACCTGCTGGCCGCCTCCTTCGGCAACGT'; ... chomp; #remove newline characters ...
    (perl.beginners)