Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 在perl中使用正则表达式解析字符串_Regex_String_Perl_Parsing - Fatal编程技术网

Regex 在perl中使用正则表达式解析字符串

Regex 在perl中使用正则表达式解析字符串,regex,string,perl,parsing,Regex,String,Perl,Parsing,我需要匹配上面这部分,这是我的字符串的其余部分。我在perl中使用正则表达式。 我试过了 但是我不能理解如何在字符串中考虑空格。这些空格可以出现在引号中的任何位置。有人能帮我吗。看一下,这个模式可以匹配字符串中的双引号: if ($line =~ /DESCR: \"([a-zA-Z0-9)\"/) { print "$1\n"; } $str = 'DESCR: "10GE SR"'; if ($str =~ /DESCR: \"([a-zA-Z0-9\s]+)\"/) {

我需要匹配上面这部分,这是我的字符串的其余部分。我在perl中使用正则表达式。 我试过了


<>但是我不能理解如何在字符串中考虑空格。这些空格可以出现在引号中的任何位置。有人能帮我吗。

看一下,这个模式可以匹配字符串中的双引号:

if ($line =~ /DESCR: \"([a-zA-Z0-9)\"/) { 
   print "$1\n";
}
$str = 'DESCR: "10GE SR"';

if ($str =~ /DESCR: \"([a-zA-Z0-9\s]+)\"/) { 
    print "$1\n";
}
它可能更简单:

if ($line =~ /DESCR: \"((?:[^\\"]|\\.)*)\"/) { 
   print "$1\n";
}
if ($line =~ /DESCR: \"((?:[^\\"]|\\.)*)\"/) { 
   print "$1\n";
}
if ( $line =~ /DESCR: "([^"]+)"/ ) { 
   print "$1\n";
}