【发布时间】:2017-02-10 04:00:02
【问题描述】:
我有一个 perl 脚本,例如如下所示:
#/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 提取上述 heredoc 打印的内容。结果应如下所示:
<<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
有人知道我的正则表达式有什么问题吗?
另一个问题:是否可以仅使用正则表达式来捕获所有未指定到 heredoc 字符串 END 的 heredocs?
【问题讨论】:
标签: javascript regex heredoc