in reply to Regex to find intersection of two words
It feels like a hack...sub inclusive { my ($big, $little) = @_; $big =~ join( '', map { "(?=.*" . join('.*', @$_) . ")" } map { ++$i & 1 ? [ map quotemeta, split // ] : () } join('', sort split //, $little) =~ /((.)\2*)/gs; ); }
Update: and here's another hack:
sub inclusive { ($chunk, $word) = @_; # sorry, no 'my' here my $r; $r = qr{ (??{ "[^\Q$word\E]*" }) ((??{ "[\Q$word\E]" })) (?{ substr($word, index($word,$1), 1) = "" }) (?(?{ length $word })(??{ $r })) | (?!) }x; scalar $chunk =~ $r; }
_____________________________________________________
Jeff[japhy]Pinyan:
Perl,
regex,
and perl
hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
|
|---|