1.正则匹配所有的a标签
<a[^>]+href="([^"]*)"[^>]*>([sS]*?)</a> 分组1和分组2即为href和value 解释: <a #匹配a标签的开始 [^>]+ #匹配a标签中href之前的内容 href="([^"]*)" #匹配href的值,并将匹配内容捕获到分组1当中 [^>]*> #匹配a标签中href之后的内容 ([sS]*?) #匹配a标签的value,并捕获到分组2当中,?表示懒惰匹配 </a> #匹配a标签的结束
2.匹配所有图标
public static string[] GetHtmlImageUrlList(string sHtmlText)
{
// 定义正则表达式用来匹配 img 标签
Regex regImg = new Regex(@"<img[^<>]*?src[s
]*=[s
]*[""']?[s
]*(?<imgUrl>[^s
""'<>]*)[^<>]*?/?[s
]*>", RegexOptions.IgnoreCase);
// 搜索匹配的字符串
MatchCollection matches = regImg.Matches(sHtmlText);
int i = 0;
string[] sUrlList = new string[matches.Count];
// 取得匹配项列表
foreach (Match match in matches)
sUrlList[i++] = match.Groups["imgUrl"].Value;
return sUrlList;
}
3.匹配号码和名字
if (!(/[wW]+/.test(form.find("[name=name]").val()))) {
alert("请输入姓名");
form.find("[name=name]").focus()
return false;
}
匹配号码:
校验2位 : /^1[3|4|5|7|8][0-9]{9}$/
校验第一位 :/^1[0-9]{10}$/