我正在尝试编写一个正则表达式来替换文本文件某些区域之间的换行符,但仅限于纯文本内容(即排除 HTML 属性内容中的文本,如 href),但在第一部分之后运气不佳。
示例输入:
AUTHOR: Me
DATE: Now
CONTENT:
This is an example. This is another example. <a href="http://www.stackoverflow/example-
link-that-breaks">This is an example.</a> This is an example. This is yet another
example.
END CONTENT
COMMENTS: 0
示例输出:
AUTHOR: Me
DATE: Now
CONTENT:
This is an example. This is another example. <a href="http://www.stackoverflow/example-link-that-breaks">This is an example.</a> This is an example. This is yet another example.
END CONTENT
COMMENTS: 0
因此,理想情况下,如果换行符出现在纯文本中,则空格会替换换行符,但如果它们在 HTML 参数内(主要是 href,如果我必须限制它,我很好)。