Re: Negate a regular expression
- From: theillien@xxxxxxxxx (Mathew Snyder)
- Date: Sat, 30 Dec 2006 03:47:12 -0500
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
.
- Follow-Ups:
- Re: Negate a regular expression
- From: Leonid Grinberg
- Re: Negate a regular expression
- References:
- Negate a regular expression
- From: Mathew Snyder
- Re: Negate a regular expression
- From: Chad Perrin
- Negate a regular expression
- Prev by Date: [bug or restriction about msgget] I have a confusion about msgget(System V message queue)
- Next by Date: Re: Strings vs Arrays
- Previous by thread: Re: Negate a regular expression
- Next by thread: Re: Negate a regular expression
- Index(es):
Relevant Pages
|
|