你通过<str>
变成这样来完成它,所以你最终得到了这样<[str]>
的数组$/->{str}
#!/usr/bin/perl --
use strict; use warnings;
my $jp = do {
use Regexp::Grammars;
qr{
# Keep the big stick handy, just in case...
<debug:on>
<debug:step>
<nocontext: > # Switch on context substring retention
# Match this...
<[str]>+
<rule: str>
( <MATCH=token1> | <MATCH=token2> ) +
<rule: token1> \<token1\>
<rule: token2> \<token2\>
}ixs};
for my $str(
q{input1: <token1> <token2> <token1>},
q{input2: <token1> <token1> <token2>},
) {
print "#<<<<# $str \n\n";
if( $str =~ $jp ){
dd(\%/) ; #/
} else {
print "## fail to match \n";
}
print "\n#>>>>#\n\n";
}
sub dd {
use Data::Dumper;
print Data::Dumper->new([@_])->Useqq(1)->Indent(1)->Dump, "\n";
}
__END__
#<<<<# input1: <token1> <token2> <token1>
$VAR1 = {
"str" => [
"<token1>",
"<token2>",
"<token1>"
]
};
#>>>>#
#<<<<# input2: <token1> <token1> <token2>
$VAR1 = {
"str" => [
"<token1>",
"<token1>",
"<token2>"
]
};
#>>>>#