单个匹配筛选:
Regex reg = new Regex(@"[\s\S]*好评率:[\s\S]*<strong>(\d{0,5}[.]\d{0,5})%</strong>", RegexOptions.IgnoreCase);
Match match = reg.Match(detail);
string year = match.Groups[1].Value;
集合匹配筛选:
string reply = client.DownloadString("http://www.steelinfo.com.cn/web/gqkx/gqkx.asp?choose=%C7%F3");
MatchCollection matchs = new Regex("<td bgcolor=\"#F7F7F7\" width=\"481\" height=\"18\">(.*?)</td>([\\s\\S]*?)<td bgcolor=\"#F7F7F7\" width=\"481\" height=\"18\"><font color=\"#FF6600\"><b>(.*?)</b></font></td>([\\s\\S]*?)</font><a href=\"(.*?)\" target=\"_blank\"><b><font color=\"#0000FF\">更多>></font></b></a></td>", RegexOptions.IgnoreCase).Matches(reply);
foreach (Match match in matchs)
{
if (DateTime.Compare(DateTime.Now.AddDays(-7), DateTime.Parse(match.Groups[1].Value)) < 0)
{
DataRow dr = dt.NewRow();
dr[0] = match.Groups[3].Value.Replace("……", "").Substring(2); ;
dr[1] = match.Groups[5].Value;
dr[2] = DateTime.Parse(match.Groups[1].Value).Month.ToString() + "-" + DateTime.Parse(match.Groups[1].Value).Day.ToString();
dt.Rows.Add(dr);
}
}
是否符合规则:
System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"^[+-]?(\d|,*)+(\.)?\d*{1}quot;);
return r.IsMatch(strNumber);
替换:
string r = Regex.Replace(key, @"[^\d.]*", "");
ikmb@163.com