0
我有一个Perl脚本,它看起来举例如下醒目定界符:正则表达式在JavaScript
#/usr/bin/perl -w
print 'My output: ';
print <<END;
Here is more content
which is printed with
heredoc style
END
print 'End of output';
现在我希望提取使用JavaScript上述定界符打印的内容。结果应该如下所示:
<<END;
Here is more content
which is printed with
heredoc style
END
我试过了<<END(.|\n)*END
。如果文档只包含一个heredoc,但如果它包含多个heredoc则不起作用。
因此,举例来说,如果我的Perl脚本如下所示:
#/usr/bin/perl -w
print 'My output: ';
print <<END;
Here is more content
which is printed with
heredoc style
END
print <<END;
Here is even more content
which is printed with
heredoc style
END
print 'End of output';
正则表达式匹配:
<<END;
Here is more content
which is printed with
heredoc style
END
print <<END;
Here is even more content
which is printed with
heredoc style
END
但它应该匹配
<<END;
Here is more content
which is printed with
heredoc style
END
和
<<END;
Here is even more content
which is printed with
heredoc style
END
有没有人有一个想法,我的正则表达式有什么问题?
另一个问题:它是否可能与正则表达式,以捕获所有heredocs它没有指定到heredoc字符串END
?
不错的解决方案。你认为可以在不指定heredoc字符串'END'的情况下捕获heredoc字符串吗? –
@BenjaminJ。寻找“反向引用”。 – Joseph
非常感谢。我的解决方案是<<((。)*); \ n(。| \ n)*?\ 1' –