日期:2014-05-20  浏览次数:20762 次

JAVA使用正则表达式取html文件中的一个标签中的value值
<html>
<head>
<meta http-equiv=content-type content="text/html; charset=utf-8">
<title>测试</title>
</head>
<body>
<script>
var playMode = function(id) {
document.getElementById(id).Mode = '2';
}
</script>
<div>
<object id="654" codebase="PenBox.ocx"
classid="clsid:B230D908-78AA-4BDA-A61F-E0D3F" width="764"
height="500">
<param name="_Version" value="65536" />
<param name="_ExtentX" value="20214" />
<param name="_ExtentY" value="13229" />
<param name="LoadDataURL"
value="http://192.168.111.16/coursedown/2012/654/mengd/49921/xmlpath/mengd1338860138788.xml" />
<param name="UserName" value="" />
<param name="MarkColor" value="255" />

</object>
<br />
<button onclick="playMode('654')">播放</button>
</div>
</body>
</html>
只要取出:http://192.168.111.16/coursedown/2012/654/mengd/49921/xmlpath/mengd1338860138788.xml

------解决方案--------------------
String str = "你的字符串";
Java code

Matcher matcher = Pattern.compile("<param\\p{Space}+name\\p{Space}*=\\p{Space}*\"LoadDataURL\"\\p{Space}+value\\p{Space}*=\\p{Space}*\"(.*?)\"").matcher(str);
        while(matcher.find())
            System.out.println(matcher.group(1));

------解决方案--------------------
have a try
Java code
String s = ...; //LZ的字符串
Matcher m = Pattern.compile("(?is).*?<param name=\"LoadDataURL\" value=\"(.*?)\".*");
while (m.find()) {
    System.out.println(m.group(1));
}