如何替换HTML <b> ... </b>标记的第一次出现

时间:2012-05-08 16:06:04

标签: java html string

String tmp = "4 days ago <b>...</b> Jon founded the video <b>Yahoo</b>! and also";

I want to remove "4 days ago <b>...</b>" from the string.

请告诉我剥离第一个标签的最佳方法是什么。

1 个答案:

答案 0 :(得分:2)

更好的方法是使用“真正的”HTML解析器。但你也可以用正则表达式来做。尝试这样的事情:

String result = tmp.replaceFirst(".*?<b>.*?</b>", "");