解析perl正则表达式

use*_*358 0 perl

if ( $_ =~ /^(\d+)_[^,]+,"",(.+)"NR"(.+)"0","",""/ )                    
{ }
elsif ( $_ =~ /^[^_]+_[^,]+,"([\d\/]+)","[^"]+","[^"]+","[^"]+","[^"]+","[^"]+",
               "[^"]+","[^"]+","[^"]+","[^"]+","[^"]+","[^"]+","[^"]+",.+/x    )
Run Code Online (Sandbox Code Playgroud)

在第一次,是重复数字一次或多次,然后_,然后重复任何不等于,一次或多次的字符,什么,"",做什么?它看起来是一个空格还是逗号是某种类型的转义字符,有点混乱,没有能力在这台机器上测试它.正则表达式中通常有逗号吗?^一开始,它是一个锚或否定整个事物?

第二个声明更糟糕

fri*_*edo 6

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
----------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

您也可以使用该模块来解析您的第二个正则表达式(我不会将其转储到此处,因为解释将非常冗长并且非常冗余.)但是如果您想要试一试,请尝试以下方法:

use strict;
use warnings;
use YAPE::Regex::Explain;

my $re = qr/^[^_]+_[^,]+,"([\d\/]+)","[^"]+","[^"]+","[^"]+","[^"]+","[^"]+",
           "[^"]+","[^"]+","[^"]+","[^"]+","[^"]+","[^"]+","[^"]+",.+/x;

print YAPE::Regex::Explain->new( $re )->explain;
Run Code Online (Sandbox Code Playgroud)