hi josh --  
 
In a message dated 7/19/2006 4:22:20 P.M. Eastern Standard Time, [EMAIL PROTECTED] writes:
 
> Gurus-
>
> I'm trying to help a co-worker on reg exp/pattern match issue.
>
> we have a set of items to go through and another set of input that's
> tested against the first.
>
> we need to check that items in the second set are a one-for-one match or
> subset of the latter.
>
>
> ie:
>
> $var1 =~ /$var2/
>
> where this returns true in a case such as $var1=Jose, Joseph, and Josh and
> $var2 will be James and Joseph
>
> when $var2 is James they need to return false and when it is Joseph both
> Jose and Joseph should return true while Josh returns false.
>
> So far we haven't found a solution in orielly and trying
>
> if( $var1 =~ m/$var2/) { print "$var2 contains $var1\n"; }
> else { print "failure on $var2 and $var1\n"; }
>
>
> has failed to work.
>
> -Josh
 
yet another approach to play around with.   again, the  \b  anchors at
the beginnings of words; easy enough to take out.     
 
C:[EMAIL PROTECTED]>perl -we "use strict;  my $str = shift;
my $re = qr/ \b (?: @{[ join '|', split ' ', shift ]} ) /x;
print qq($re \n);  print(qq(NO match \n)), exit if $str !~ /$re/x;
print qq(match: $`\{$&\}$' \n)"
   "Joseph James Joshua"   "ose Josh"
(?x-ism: \b (?: ose|Josh ) )
match: Joseph James {Josh}ua
 
C:[EMAIL PROTECTED]>perl -we "use strict;  my $str = shift;
my $re = qr/ \b (?: @{[ join '|', split ' ', shift ]} ) /x;
print qq($re \n);  print(qq(NO match \n)), exit if $str !~ /$re/x;
print qq(match: $`\{$&\}$' \n)"
   "Joseph James"   "Jam Jose Josh"
(?x-ism: \b (?: Jam|Jose|Josh ) )
match: {Jose}ph James
 
C:[EMAIL PROTECTED]>perl -we "use strict;  my $str = shift;
my $re = qr/ \b (?: @{[ join '|', split ' ', shift ]} ) /x;
print qq($re \n);  print(qq(NO match \n)), exit if $str !~ /$re/x;
print qq(match: $`\{$&\}$' \n)"
   "Joseph James"   "Josh"
(?x-ism: \b (?: Josh ) )
NO match
 
C:[EMAIL PROTECTED]>perl -we "use strict;  my $str = shift;
my $re = qr/ \b (?: @{[ join '|', split ' ', shift ]} ) /x;
print qq($re \n);  print(qq(NO match \n)), exit if $str !~ /$re/x;
print qq(match: $`\{$&\}$' \n)"
   "Joseph James"   "ose"
(?x-ism: \b (?: ose ) )
NO match
regards -- bill walters  
 
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to