Re: regex matching
- From: niall.macpherson@xxxxxxxxxxxx
- Date: 31 May 2006 03:56:35 -0700
niall.macpher...@xxxxxxxxxxxx wrote:
There shouldn't be a situation where you would want do something like
if($string =~ /cat/ && $string !~ /catapult/)
{
print 'String matches cat but not catapult';
}
since you could quite easily construct a single regular expression
which would suit your needs rather than testing a match and a
non-match.
Here's one way you could do it (as usual TIMTOWTDI) using capturing
parentheses (untested)
if($string =~ /cat(\S)/)
{
if($1 eq 'apult')
{
print 'It has a cat but I do not want catapult'
}
else
{
print "I do want $string";
}
}
else
{
print "Do not want $string as it does not contain cat";
}
.
- References:
- regex matching
- From: cknipe
- Re: regex matching
- From: niall . macpherson
- regex matching
- Prev by Date: Re: regex matching
- Next by Date: hash and array question
- Previous by thread: Re: regex matching
- Next by thread: Re: regex matching
- Index(es):
Relevant Pages
|
|