Re: regular expression help



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

.