日期:2014-05-17 浏览次数:20874 次
String content="<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
"<head>\n" +
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n" +
"<meta content=\"求助 java获 html网页编码字段 正则表达式 Java Web 开发\" name=\"Keywords\"/>...\n";
Pattern pattern=Pattern.compile("<meta\\s+http-equiv=\"Content-Type\"\\s+content=\"[\\s\\S]*?charset=(\\S+?)\"/>");
Matcher matcher=pattern.matcher(content);
if(matcher.find()){
System.out.println(matcher.group(1));
}