글꼴 이름을 추출하려고합니다. 예 :
String htmlContent = "<font face=\"impact\">Hdjdjdisid <font style=\"background-color:#ff0000\"> shejej</font></font>";
에:
impact
이것은 내가 웹에서 찾은 것이지만 모든 태그의 콘텐츠를 반환하고 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));
}
얼굴 이름 만 추출하려면 어떻게해야합니까?
이 간단한 경우 다음과 같이 패턴을 조정하십시오.
<font[^>]+face="([^"]+)"
자바에서 사용하기 위해 이스케이프 :
String pattern = "<font[^>]+face=\"([^\"]+)\"";
그러나 다른 사람들이 지적했듯이 정규식으로 html을 구문 분석하지 마십시오.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다