62,267
社区成员
发帖
与我相关
我的任务
分享
string source = @"<a href=""www.baidu.com"">百度</a>";
Regex reg = new Regex(@"<a href=""(?<web>[^""]+)"">百度");
MatchCollection mc = reg.Matches(source);
foreach (Match m in mc)
{
MessageBox.Show(m.Groups["web"].Value);
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs"
Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
</head>
<body>
<div id="show">
<a href="www.baidu.com">百度</a>
<a href="www.sina.com">新浪</a>
<a href="www.google.cn">谷歌</a>
<a href="www.souhu.com">搜狐</a>
</div>
</body>
</html>
Dictionary<string, string> dicstr = new Dictionary<string, string>();
string strfromtxt = File.ReadAllText(@"C:\1.txt", Encoding.GetEncoding("GB2312"));
string res = @"(?is)<a\s*href=""(?<href>([^>]*))""\s*>(?<value>(.*?))</a>";
MatchCollection matches = Regex.Matches(strfromtxt, res);
foreach (Match match in matches)
{
dicstr.Add(match.Groups["value"].Value.Trim(), match.Groups["href"].Value.Trim());//数据结果在dicstr
}
$("a").each(function(){
if($(this).html()=="百度")
{
alert($(this).attr("href"));
}
});