Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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_Arrays_Perl_Pattern Matching - Fatal编程技术网

Regex 在Perl中将正则表达式匹配保存到数组中

Regex 在Perl中将正则表达式匹配保存到数组中,regex,arrays,perl,pattern-matching,Regex,Arrays,Perl,Pattern Matching,我希望你能告诉我我做错了 例如,我有: my $text = "<some tag> stuff here> </some tag> mer mer <some tag> 'more stuff' </some tag>"; @b =($text =~ m/s(.)uff/gsi); print "array B, size: ", @b+0, ", elements: "; print join (" ,", @b); pr

我希望你能告诉我我做错了

例如,我有:

my $text = "<some tag>  stuff here> </some tag> mer mer <some tag> 'more stuff' </some tag>";

 @b =($text =~ m/s(.)uff/gsi);
 print "array B, size: ",  @b+0,  ", elements: ";
 print join (" ,", @b);
 print "\n";


 @c =($text =~ m/<some tag>(.+)<\/some tag>/g);
 print "array C, size: ",  @c+0,  ", elements: ";
 print join (", ", @c);
 print "\n"; 
为什么要跳过它?

/(.+?)/
/<some tag>(.+?)<\/some tag>/

如果不能嵌套,则将执行此操作。

为了在字符串中找到最短的匹配项,请使用非贪婪搜索
(.+?)

否则,对于最长的匹配字符串,可以进行贪婪搜索
(.+)

为了更好地理解,请参考链接


因此,正确的答案应该是池上给出的答案

现在是2013年。使用XML解析器。
size 2: , elements stuff here , 'more stuff'
/<some tag>(.+?)<\/some tag>/