如何使用Regex删除这些标记之间的换行符?
我确实看到了另一个解决方案,但它使整个文件没有新行。我只需要一个没有新行的特定部分 我正在尝试删除这些标记之间的间距,以便它们彼此相邻,如下所示:如何使用Regex删除这些标记之间的换行符?,regex,Regex,我确实看到了另一个解决方案,但它使整个文件没有新行。我只需要一个没有新行的特定部分 我正在尝试删除这些标记之间的间距,以便它们彼此相邻,如下所示: <a rel="nofollow noopener" style="display:inline; text-decoration: none;" href=""><img border="0" class="full" height="auto" width="300" alt="" src="http://via.placeho
<a rel="nofollow noopener" style="display:inline; text-decoration: none;" href=""><img border="0" class="full" height="auto" width="300" alt="" src="http://via.placeholder.com/600x338"></a><a rel="nofollow noopener" style="display:inline; text-decoration: none;" href=""><img border="0" class="full" height="auto" width="300" alt="" src="http://via.placeholder.com/600x338"></a><a rel="nofollow noopener" style="display:inline; text-decoration: none;" href=""><img border="0" class="full" height="auto" width="300" alt="" src="http://via.placeholder.com/600x338"></a><a rel="nofollow noopener" style="display:inline; text-decoration: none;" href=""><img border="0" class="full" height="auto" width="300" alt="" src="http://via.placeholder.com/600x338"></a>
它们目前看起来是这样的:
<a rel="nofollow noopener" style="display:inline; text-decoration: none;" href="">
<img border="0" class="full" height="auto" width="300" alt="" src="http://via.placeholder.com/600x338">
</a>
<a rel="nofollow noopener" style="display:inline; text-decoration: none;" href="">
<img border="0" class="full" height="auto" width="300" alt="" src="http://via.placeholder.com/600x338">
</a>
<a rel="nofollow noopener" style="display:inline; text-decoration: none;" href="">
<img border="0" class="full" height="auto" width="300" alt="" src="http://via.placeholder.com/600x338">
</a>
<a rel="nofollow noopener" style="display:inline; text-decoration: none;" href="">
<img border="0" class="full" height="auto" width="300" alt="" src="http://via.placeholder.com/600x338">
</a>
此模式应该有效:(?)\s*\s*(?=。只需将匹配项替换为”
以下是我在注释中建议的正则表达式示例,我添加了\t
和\s{2,}
以拉出制表符和2个或更多空格字符
let temp=`
`;
console.log(temp.replace(/[\r\n |\r |\n |\t]/g',).replace(/\s{2,}/g',)
try[\r\n |\r\n]
要查找换行符,您可能需要使用g
标志来获取所有换行符注意:如果这是您正在进行的所有解析,那么RegEx就可以了,但是如果您正在做的不仅仅是这些,那么您可能希望查看其他解决方案。您的模式可能会干扰标记的内容。可能会更改类似于
到
是无意的。最好将其限制在标记的外部。出于某种原因,“first”和“last”之间的多个空格没有显示,但它就在那里。@emsimpson92你是对的,这就是为什么我把它作为一个附加调用,这样就很容易拉出。@emsimpson92还用一个空格替换多个空格,所以在first\u last
的实例中什么都不会发生,而在first\uuuuuuuuuuuuuuuuuuuuuu last
的情况下,它将成为first_last
这在大多数情况下都应该是好的。是的,在大多数情况下都是好的。我只是想指出一下,万一OP需要的话。