I, too, am confused by the whole question of the 'complimentary' (or complementary, or converse) question.
Maybe the question can be usefully (and symmetrically) reframed as "Are there any characters in common at the beginnings of both strings?". This could be answered by index as well as by a regex.
>perl -wMstrict -le
"my @set = ('abc.def.ghi', 'abc', '...');
;;
for my $p (@set) {
for my $q (@set) {
print qq{'$p', '$q' common at start? },
$q =~ m{ \A \Q$p\E }xms || $p =~ m{ \A \Q$q\E }xms
? 'yes' : 'no';
}
}
;;
print '';
for my $p (@set) {
for my $q (@set) {
print qq{'$p', '$q' common at start? },
0 == index($p, $q) || 0 == index($q, $p) ? 'yes' : 'no';
}
}
"
'abc.def.ghi', 'abc.def.ghi' common at start? yes
'abc.def.ghi', 'abc' common at start? yes
'abc.def.ghi', '...' common at start? no
'abc', 'abc.def.ghi' common at start? yes
'abc', 'abc' common at start? yes
'abc', '...' common at start? no
'...', 'abc.def.ghi' common at start? no
'...', 'abc' common at start? no
'...', '...' common at start? yes
'abc.def.ghi', 'abc.def.ghi' common at start? yes
'abc.def.ghi', 'abc' common at start? yes
'abc.def.ghi', '...' common at start? no
'abc', 'abc.def.ghi' common at start? yes
'abc', 'abc' common at start? yes
'abc', '...' common at start? no
'...', 'abc.def.ghi' common at start? no
'...', 'abc' common at start? no
'...', '...' common at start? yes
|