Re: regular expression help
- From: Purl Gurl <purlgurl@xxxxxxxxxxxx>
- Date: Fri, 30 Mar 2007 12:20:52 -0700
bpatton wrote:
(snipped)
How do I do an 'and' in regular expressions?
$string = '-Dz=a =Dy=b -Dx=c -Dw=d -Dv=e -Du=f -Dt=g -Ds=h';
$search = '-Dx=(c|g|h)'; # this came from hash value
If ($string =~ /$search/) { # This works fine
Now how would I do an 'and' in any order
$search = '-Ds=(a|b|c)&&-Du=(f|g|h)'; # need both -Du and -Ds in any
I can't separate the $search. It must always be a single string.
This is untrue.
#!perl
$string = "-Ds=a-Du=h";
$search = '-Ds=(a|b|c)&&-Du=(f|g|h)';
($search1, $search2) = split (/&&/, $search);
if (($string =~ /$search1/) && ($string =~ /$search2/))
{ print "match"; }
PRINTED RESULTS:
match
Purl Gurl
.
- References:
- regular expression help
- From: bpatton
- regular expression help
- Prev by Date: Re: regular expression help
- Next by Date: Re: Isolate lines in a text file and perform replacements
- Previous by thread: Re: regular expression help
- Next by thread: Re: regular expression help
- Index(es):