Re: Negate a regular expression
- From: "DJ Stunks" <DJStunks@xxxxxxxxx>
- Date: 29 Dec 2006 21:32:31 -0800
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
.
- References:
- Negate a regular expression
- From: Mathew Snyder
- Negate a regular expression
- Prev by Date: Re: Negate a regular expression
- Next by Date: Re: Negate a regular expression
- Previous by thread: Re: Negate a regular expression
- Next by thread: Re: Negate a regular expression
- Index(es):
Relevant Pages
|