正则表达式使用
—-代码—-
using System.Text.RegularExpressions;
string regexStr = "href\\s*=\\s*\"([^\"]*)\"";
Regex regex = new Regex (regexStr, RegexOptions.IgnoreCase);
MatchCollection matches = regex.Matches(text);
foreach (Match match in matches)
{
//do sth…
}
—-正则表达式收集—-
//———————————————————–
//形如 href="http://msdn.microsoft.com/netframework/"的连接
//—-注意Group的使用\"([^\"]*)\"
//—-如果使用Groups[1],会返回 http://msdn.microsoft.com/netframework/
//—-如果使用Groups[0],会返回 href="http://msdn.microsoft.com/netframework/"
string regexStr = "href\\s*=\\s*\"([^\"]*)\""
foreach (Match match in matches)
{
string myURL = match.Groups[1];
}
