<li id="student" class="c1">
<span>家庭住址:</span>
<div>
<em>四川成都</em> <i class="c2">|</i>
</div>
</li>
想匹配出:四川成都,这个正则怎么写?谢了
<span>家庭住址:</span>
<div>
<em>四川成都</em> <i class="c2">|</i>
</div>
</li>
想匹配出:四川成都,这个正则怎么写?谢了
<!DOCTYPE HTML>
<html>
<head>
<meta charset="gb2312" />
<title></title>
<style>
</style>
</head>
<body>
<li id="student" class="c1">
<span>家庭住址:</span>
<div>
<em>四川成都</em> <i class="c2">|</i>
</div>
</li> <script>
function $(el){
return typeof el == 'string' ? document.getElementById(el) : el;
}
var s = $('student').innerHTML;
var re = /<em>(.+)<\/em>/g;
re.test(s);
alert(RegExp.$1)
</script>
</body>
</html>
[/Quote]
<span>家庭住址:</span>
<div>
<em>四川成都</em> <i class=""c2"">|</i>
</div>
</li>";
Match match = Regex.Match(s, @"(?is)<li id=""student"".*?<em>(.+?)</em>");
Response.Write(match.Groups[1].Value);
<li id="student" class="c1">
<span>家庭住址:</span>
<div>
<em>四川成都</em> <i class="c2">|</i>
</div>
</li>
这底下在出现一对
<li class="c3">
<span>升高:</span><em>172</em>cm
</li>
然后我想匹配出“四川成都”谢谢
Match match = Regex.Match(s, @"<em>(.*?)</em>");
string gets = ""; while (match.Success)
{
for (int i = 0; i < match.Groups.Count; i++)
{
Group group = match.Groups[i];
gets += match.Groups[i+1].Value+"|";//四川成都|172 ,加了个分隔符|
}
//进行下一次匹配
match = match.NextMatch();
}
<span>家庭住址:</span>
<div>
<em>四川成都</em> <i class=""c2"">|</i>
</div>
</li>
<li class=""c3"">
<span>升高:</span><em>172</em>cm
</li>
";
MatchCollection matches = Regex.Matches(s, @"(?is)<li[^>]*>.*?<em>(.+?)</em>.*?</li>");
foreach (Match match in matches)
Response.Write(match.Groups[1].Value + "<br/>");