如何仅从文本中删除标签?

问候所有,我有一个文本可能包含标签,如:

 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("","");//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( "", "" ); 

如果你的意思是标签与其他属性,那么你需要

 String source = "blargle"; source.replaceAll( "]*>", "" ); 
 System.out.println(s.replaceAll("", "")); 

你去: str.replaceAll("","")

通常,使用正则表达式修复HTML是一个坏主意 – 讨论请参阅此处的最佳答案使用正则表达式解析HTML:为什么不呢? – 即使看起来它可能很快。 请尝试使用您选择的语言中的DOM解析器,并将节点替换为其子文本节点。

 if (message.contains("", "").replaceAll("", ""); }