问候所有,我有一个文本,可能包含以下<a></a>标签:
hello this is a link <a href="www.google.com"> www.google.com </a> please visit it.
Run Code Online (Sandbox Code Playgroud)
我想删除这些标记并将它们保持在它们之间:
hello this is a link www.google.com please visit it.
Run Code Online (Sandbox Code Playgroud)
, 怎么做 ?
仅适用于<a>和</a>标签
String source = "<a>blargle</a>";
source.replaceAll( "</?a>", "" );
Run Code Online (Sandbox Code Playgroud)
如果你的意思是<a>带有其他属性的标签,那么你需要
String source = "<a>blargle</a>";
source.replaceAll( "</?a[^>]*>", "" );
Run Code Online (Sandbox Code Playgroud)
String str="<a>sadasd</a>";
str.replaceAll("<a>","").replaceAll("</a>","");//sadasd
Run Code Online (Sandbox Code Playgroud)
要么
str.replaceAll("</?a>","");//sadasd
Run Code Online (Sandbox Code Playgroud)
或者最好的方法是选择Jsoup Cleaner
String str = "hello this is a link <a href='www.google.com'> www.google.com </a> please visit it";
String safe = Jsoup.clean(str, Whitelist.simpleText());
System.out.println(safe);//hello this is a link www.google.com please visit it
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5405 次 |
| 最近记录: |