CPAN 模块YAPE::Regex::Explain可用于解析和解释您不理解的 Perl 正则表达式。这是您的第一个正则表达式的输出:
(?-imsx:^(\d+)_[^,]+,"",(.+)"NR"(.+)"0","","")
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
^ the beginning of the string
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
_ '_'
----------------------------------------------------------------------
[^,]+ any character except: ',' (1 or more times
(matching the most amount possible))
----------------------------------------------------------------------
,"", ',"",'
----------------------------------------------------------------------
( group and capture to \2:
----------------------------------------------------------------------
.+ any character except \n (1 or more times
(matching the most amount possible))
----------------------------------------------------------------------
) end of \2
----------------------------------------------------------------------
"NR" '"NR"'
----------------------------------------------------------------------
( group and capture to \3:
----------------------------------------------------------------------
.+ any character except \n (1 or more times
(matching the most amount possible))
----------------------------------------------------------------------
) end of \3
----------------------------------------------------------------------
"0","","" '"0","",""'
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
你也可以使用该模块来解析你的第二个正则表达式(我不会在这里转储它,因为解释会很长而且非常多余。)但是如果你想试一试,试试这个:
use strict;
use warnings;
use YAPE::Regex::Explain;
my $re = qr/^[^_]+_[^,]+,"([\d\/]+)","[^"]+","[^"]+","[^"]+","[^"]+","[^"]+",
"[^"]+","[^"]+","[^"]+","[^"]+","[^"]+","[^"]+","[^"]+",.+/x;
print YAPE::Regex::Explain->new( $re )->explain;