Re: regex matching




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";
}

.



Relevant Pages

  • Re: A-6 crash after launch?
    ... They had some footage of some cat launches gone wrong. ... off the waist catapult of a carrier and started losing altitude almost ...
    (rec.aviation.military.naval)
  • Re: Lift Pixies
    ... with geese because many water birds look alike. ... geese seldom want to go in the ... Cat goes on Catapult, friend fires said Catapult ...
    (rec.aviation.military)
  • Re: Learning flying vs. driving
    ... the family cat to piss on my shoes. ... Put CAT-nip in the CATapult. ... said neighbour, (open or closed, it's messy if she ...
    (rec.aviation.student)
  • Re: Learning flying vs. driving
    ... the family cat to piss on my shoes. ... Put CAT-nip in the CATapult. ... said neighbour, (open or closed, it's messy if she ...
    (rec.aviation.student)
  • Re: Learning flying vs. driving
    ... cat to piss on my shoes. ... Put CAT-nip in the CATapult. ... said neighbour, (open or closed, it's messy if she ...
    (rec.aviation.student)