如何仅从文本中删除标签?
hello this is a link https://stackoverflow.com/questions/4614567/how-to-remove-the-a-tags-only-from-a-text/www.google.com please visit it.
我想删除这些标签并将它们保持在它们之间:
hello this is a link https://stackoverflow.com/questions/4614567/how-to-remove-the-a-tags-only-from-a-text/www.google.com please visit it.
, 怎么做 ?
String str="sadasd"; str.replaceAll("","").replaceAll("","");//sadasd
要么
str.replaceAll("?a>","");//sadasd
或者最好的方法是选择Jsoup Cleaner
String str = "hello this is a link https://stackoverflow.com/questions/4614567/how-to-remove-the-a-tags-only-from-a-text/www.google.com please visit it"; String safe = Jsoup.clean(str, Whitelist.simpleText()); System.out.println(safe);//hello this is a link https://stackoverflow.com/questions/4614567/how-to-remove-the-a-tags-only-from-a-text/www.google.com please visit it
String source = "blargle"; source.replaceAll( "?a>", "" );
String source = "blargle"; source.replaceAll( "?a[^>]*>", "" );
System.out.println(s.replaceAll("?a>", ""));
你去: str.replaceAll("?a>","")
通常,使用正则表达式修复HTML是一个坏主意 – 讨论请参阅此处的最佳答案使用正则表达式解析HTML:为什么不呢? – 即使看起来它可能很快。 请尝试使用您选择的语言中的DOM解析器,并将节点替换为其子文本节点。
if (message.contains("", "").replaceAll("", ""); }