【发布时间】:2014-01-28 15:42:39
【问题描述】:
我回来跟进this question。 假设我有文字
====Example 1====
Some text that I want to get that
may include line breaks
or special ~!@#$%^&*() characters
====Example 2====
Some more text that I don't want to get.
并使用$output = ($text =~ ====Example 1====\s*(.*?)\s*====); 尝试获取从“====Example 1====”到“Example 2”之前的四个等号的所有内容。
根据我所看到的on this site、regexpal.com 并通过自己运行它,Perl 找到并匹配文本,但 $output 仍然为空或被分配为“1”。我很确定我在捕获括号上做错了什么,但我不知道是什么。任何帮助,将不胜感激。 我的完整代码是:
$text = "====Example 1====\n
Some text that I want to get this text\n
may include line breaks\n
or special ~!@#$%^&*() characters\n
\n
====Example 2====]\n
Some more filler text that I don't want to get.";
my ($output) = $text =~ /====Example 1====\s*(.*?)\s*====/;
die "un-defined" unless defined $output;
print $output;
【问题讨论】:
-
我的 ($output) = $text =~ /====示例 1====\s*(.*?)\s*====/;