I have an HTML page and I want to fetch the result between two tags <开发者_JAVA百科;b>
and <BR>
:
<b>Defendants Name:</b>Donahue, Leah A <BR>
What is the regular expression to fetch the words between these two tags?
I think this could work:
String str = "<b>Defendants Name:</b>Donahue, Leah A <BR>";
Pattern pattern = Pattern.compile(".*<b>(.*)<BR>.*", Pattern.UNIX_LINES);
Matcher m = pattern.matcher(str);
if (m.matches() == true)
{
System.out.println(m.group(1));
}
And should print
"Defendants Name:Donahue, Leah A " (excluding the quotes).
You shouldn't use regexps for parsing HTML, use an HTML parser instead. Have a look at jsoup.
精彩评论