gpt4 book ai didi

java - 如何修复正则表达式以剥离
标签,其中包含\n ?

转载 作者:行者123 更新时间:2023-12-01 06:01:40 24 4
gpt4 key购买 nike

我是一个java正则表达式新手,所以我在这里询问你是否可以帮助我解决这个问题。所以我有一串带有 block 引用标签的单词,如下所示:

<blockquote>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum neque nisi, accumsan id lacus vitae, eleifend hendrerit dui. Aliquam erat volutpat. Vestibulum quis tincidunt neque. Etiam dignissim molestie lorem non commodo.\n</blockquote>\nDuis porta consectetur turpis, rutrum pellentesque nibh porttitor quis. Suspendisse porta mollis ullamcorper. Vivamus aliquam, diam id molestie eleifend, ipsum quam interdum tortor, placerat feugiat urna elit vel metus. Phasellus aliquet metus tincidunt leo tempus, sit amet hendrerit mi malesuada. Aenean maximus a purus quis auctor. Vivamus risus metus, rhoncus ut accumsan id, efficitur sit amet nunc. Sed quis urna a ante ornare laoreet. Nullam auctor gravida mauris ut aliquam.\n\n<blockquote>Aliquam erat volutpat. Vestibulum quis tincidunt neque. Etiam dignissim molestie lorem non commodo. Nam id cursus eros. Sed tempus tempor nulla id venenatis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In in varius massa\n</blockquote>Cras congue metus nulla, a laoreet lorem bibendum dictum. Aenean nec velit porta purus ornare dictum sed dictum massa. Suspendisse imperdiet neque nec lorem commodo, ut congue nisl placerat. Maecenas nec justo feugiat, faucibus turpis at, tincidunt dui. Fusce tincidunt suscipit lectus nec dictum.\n

我需要删除 block 引用标签并删除其中的内容,并删除 block 引用内的\n 。我需要在 TextView 中显示它。到目前为止,这就是我所做的:

public static String replaceAllBlockQuoteTags(String postText) {
return postText.replaceAll("<\\/?\\s*" + BLOCKQUOTE_TAG + ".*?>", "").replaceAll("<\\/?\\n*\" + BLOCKQUOTE_TAG + \"");
}

但它并没有删除\n。有什么想法如何解决这个问题吗?我将不胜感激你的回应。谢谢!

最佳答案

您可以使用以下函数,它将删除 block 引号和换行符

public static String replaceAllBlockQuoteTags(String postText) {
return postText.replace("\n</blockquote>", "").replace("<blockquote>", "");
}

关于java - 如何修复正则表达式以剥离 <blockquote></blockquote> 标签,其中包含\n ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56984634/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com