Hi!
let say i have a string like this "neverMind<b>What is up</b>neverMind
" and I want to take out the What is up using regexp with JAVA. Someone told me that using matcher will be the best. Can anyone show me how to do it using Matcher?
Other solutions are welcome too!
Thanks!
views:
51answers:
1
+3
A:
If your string is simple like this all the time, you could use the java Pattern
indeed. But if your strings get more complicated and you want to extract contents from nested structures, you should really use a HTML parser.
For choosing the right parser look at this question: Which HTML parser is best.
If you stay with patterns, your regex will look like this:
Pattern pattern = Pattern.compile( "<b>(.*?)</b>" );
Matcher m = pattern.matcher( "neverMind<b>What is up</b>neverMind" );
if( m.find() ) {
String theStringYouAreLookingFor = m.group( 1 );
}
tangens
2010-05-16 10:20:45
+1 for directly answering the question, and also suggesting a better approach...
Martin Milan
2010-05-16 10:30:51