1
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.

Please let me know what is the best way to strip till the first tag.

Kai
  • 38,985
  • 14
  • 88
  • 103
Nick
  • 185
  • 1
  • 12

1 Answers1

2

The better way is to use "real" HTML parser. But you can do it with regular expression as well. Try something like this:

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

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • This is a non-lazy one which might be more efficient: String result = tmp.replaceFirst("[^>]*>[^>]*>", ""); – dragon66 May 08 '12 at 19:09