[英]How to extract font tag from HTML?
I'm tring to extract the font face name eg: 我正在尝试提取字体名称,例如:
String htmlContent = "<font face=\"impact\">Hdjdjdisid <font style=\"background-color:#ff0000\"> shejej</font></font>";
to: 至:
impact
This is what I found on the web but it's returning all the tags' content and i want only the face
name. 这是我在网上找到的,但是它返回了所有标签的内容,我只想要face
名称。
String pattern = "<FONT (.*?)>";
Pattern p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(htmlContent);
if (m.find()) {
// prints: <FONT FACE="Verdana" SIZE="12"> My Name is xyz </FONT></P>
System.out.println(m.group());
// prints: FACE="Verdana" SIZE="12"
System.out.println(m.group(1));
}
How can I extract only the face name? 如何仅提取人脸名称?
In this simple case, adjust your pattern like this: 在这种简单的情况下,请像这样调整您的模式:
<font[^>]+face="([^"]+)"
escaped for use with java: 转义与Java一起使用:
String pattern = "<font[^>]+face=\"([^\"]+)\"";
But as others pointed out: dont parse html with regex. 但正如其他人指出的那样:不要使用正则表达式解析html。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.