Diego Riano wrote: > I am trying to put it in a better way, (I hope :-)) > > What I am trying to do is check if two patterns could recognize the same > string, for example: > $pattern1=[ag]oprs[cd]xxxxx9; > $pattern2=[agpr]oprs; > > these two patterns would recognize, both, a set of strings. however > there will be some strings that only $pattern2 will match and viceversa. > So, How can I compare these two patterns to say if they are similar or > the same? > > thanks again
It would be somewhat difficult, I suspect. Perhaps by taking substrings on their canonical forms, after compiling to regex. Unfortunately, matching comparisions: do not guarantee that one is actually a subpattern of the other. You already provided the answer to that question when you indicated that their matching sets each had a subset that was not contained in the union. Unfortunately, a pattern can match another pattern without the other pattern being a sub-pattern: #!perl -w use strict; use warnings; my $pat1 = qr /Hi.*?\sBye/; my $pat2 = qr /(Hi|[Hh]ello).*?\sBye--I'll sure miss you\!/; print "$pat1 is the \"smaller\" pattern\n"; print "$pat2 is the \"larger\" pattern\n"; print "\n"; if ($pat2 =~ $pat1) { print "$pat2 contains $pat1\n"; } else { print "$pat2 matches $pat1\n"; } print "\n"; my $test = $pat1; chop $test; # kill the closing paren of the canonical regex if ($test eq substr($pat2, 0, length($test))) { print "$pat1 is a true sub-pattern of $pat2\n"; } else { print "$pat1 is not a true sub-pattern of $pat2\n"; } print "\n"; my $string1 = "Hello, Bye--I'll sure miss you!"; if ($string1 =~ $pat1) { print "$string1 matches $pat1\n"; } else { print "$string1 does not match $pat1\n"; } if ($string1 =~ $pat2) { print "$string1 matches $pat2\n"; } else { print "$string1 does not match $pat2\n"; } Hi There,podner E:\d_drive\perlStuff>pat_holds.pl (?-xism:Hi.*?\sBye) is the "smaller" pattern (?-xism:(Hi|[Hh]ello).*?\sBye--I'll sure miss you!) is the "larger" pattern (?-xism:(Hi|[Hh]ello).*?\sBye--I'll sure miss you!) matches (?-xism:Hi.*?\sBye) (?-xism:Hi.*?\sBye) is not a true sub-pattern of (?-xism:(Hi|[Hh]ello).*?\sBye-- I'll sure miss you!) Hello, Bye--I'll sure miss you! does not match (?-xism:Hi.*?\sBye) Hello, Bye--I'll sure miss you! matches (?-xism:(Hi|[Hh]ello).*?\sBye--I'll sure miss you!) Hi There,podner E:\d_drive\perlStuff> Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]