我回來後跟進到this question。 假設我有文字括號文本捕獲(Perl RegEx)
====Example 1====
Some text that I want to get that
may include line breaks
or special [email protected]#$%^&*() characters
====Example 2====
Some more text that I don't want to get.
,並使用$output = ($text =~ ====Example 1====\s*(.*?)\s*====);
,試圖從「====例1個====」四個等號得到的一切權利「示例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 [email protected]#$%^&*() 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;
我($輸出) = $ text =〜/ ====例子1 ==== \ s *(。*?)\ s * ==== /; –