1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
use v5.14;
use strict;
use warnings;
use Regexp::Assemble;
use Data::Dumper;
my $re = Regexp::Assemble->new(flags => 'i')->track(1);
foreach my $reg (
'(?^ux: Coneheads(?^ux: [^\\p{Alnum}] )(?^ux: [^\\p{Alnum}] )(?^ux: [^\\p{Alnum}] )Dan(?^ux: [^\\p{Alnum}] )Aykroyd(?^ux: [^\\p{Alnum}] )Comedy(?^ux: [^\\p{Alnum}] )Eng )|(?^ux: Coneheads(?:[+]|%20)-(?:[+]|%20)Dan(?:[+]|%20)Aykroyd(?:[+]|%20)Comedy(?:[+]|%20)Eng)',
# 'Coneheads(?^ux: [^\\p{Alnum}] )(?^ux: [^\\p{Alnum}] )(?^ux: [^\\p{Alnum}] )Dan(?^ux: [^\\p{Alnum}] )Aykroyd(?^ux: [^\\p{Alnum}] )Comedy(?^ux: [^\\p{Alnum}] )Eng',
# 'Coneheads(?:[+]|%20)-(?:[+]|%20)Dan(?:[+]|%20)Aykroyd(?:[+]|%20)Comedy(?:[+]|%20)Eng',
'(?^u:Coneheads\\ 1993)',
) {
$re->add( $reg );
}
foreach my $string (
"Coneheads - Dan Aykroyd Comedy Eng",
"Coneheads+-+Dan+Aykroyd+Comedy+Eng",
"Coneheads%20-%20Dan%20Aykroyd%20Comedy%20Eng",
"Coneheads 1993",
) {
if( $string =~ /$re/ ) {
say "matched $string";
if( my $matched = $re->matched() ) {
say "matched with: $matched";
}
if( my $matched = $re->source($^R) ) {
say "\$^R: $^R";
say "match source: $matched";
}
say "work around: ", get_source($re, $string);
}
else {
say "no match on $string";
say "get_source returns: ", get_source($re, $string);
}
say "-" x 70;
}
print Dumper $re;
sub get_source {
my ($re, $string) = @_;
foreach my $r ( @{$re->{mlist}} ) {
if( $string =~ /$r/ ) {
return $r;
}
}
return;
}
|