//=====================Begin1========================
试验字符串
stringstrTmp=.Empty;
正则表达式tmpStr.Empty;
取出指定HTML标记中的匹配项的值RegexOptions.IgnoreCase忽略大小写,RegexOptions.Multiline忽略多行显示,
tmpStr="<title>([^<]*)</title>"获取<title>之间内容
strTmp@"<addkey='ConnectionString'value='server=localhost;database=数据库名;uid=sa;pwd=;pooling=true'/>";
获取“database=”与“;”号之间的字符串:database=(.*);database=([^;]*);;
MatchTitleMatchRegex.Match(strTmp,tmpStr,RegexOptions.IgnoreCase|RegexOptions.Multiline);
如下例子作语法参考用获取size的值,实际应用可能不会如此复杂><fontcolor='red'size=6>WebForm3</font><;
tmpStr<(w+s+w+[=]+[']+w+[']+s+[size=]+d)>RegexOptions.Multiline);
取出匹配项的值tmpStrTitleTitleMatch.Groups[1].Value;
替换掉HTML页中所有HTML标记Label1.TextRegex.Replace(Label1.Text.Trim(),<.+?>,0)">"")+*********].Value;
判断匹配正则表达式是否成功if(Regex.Match(tmpStr,0)">).Success)
{
操作}=====================End1========================
=====================Begin2========================webDocContent<ahref=http://www.xxx.xxx/college/pages/default.htmtarget=_blank>师资队伍</A>解释下面正则表达式:[s]表示匹配空格字符,"+"表示连接strPatterna[s]+href=(?<Link>[^s>]+)[^>]*>(?<Text>[^<]*)</a>获取链接显示的文字MatchCollectionMatchesRegex.Matches(webDocContent,strPattern,0)">RegexOptions.Compiled);
foreach(MatchNextMatchinMatches)
URLNextMatch.Groups[Link].Value.ToString().Trim();
URLTextText].Value.ToString().Trim();
Response.Write(URL****);
Response.Write(URLText);
}=====================End2========================
=====================Begin3========================strPageContent.Empty;
StreamReadersrPagenewStreamReader(e:save.txtgb2312));
strPageContentsrPage.ReadToEnd();
srPage.Close();
(/s)*表示0或多个空格符、回车符等,*表示比配0或多个。(.*?)表示除回车符外的所有信息MatchCollectionTitleMatchsRegex.Matches(strPageContent,0)"><tdwidth="85%"class="common_text">((/s)*(.*?)(/s)*(.*?)(/s)*(.*?)(/s)*(.*?)(/s)*)</td>RegexOptions.Multiline);
inttmpNum0循环正则表达式所获取的,满足表达式的内容集合TitleMatchs)
++tmpNum;
Label1.Text+=<br>****].Value;
}=====================End3========================
试验字符串
stringstrTmp=.Empty;
正则表达式tmpStr.Empty;
取出指定HTML标记中的匹配项的值RegexOptions.IgnoreCase忽略大小写,RegexOptions.Multiline忽略多行显示,
tmpStr="<title>([^<]*)</title>"获取<title>之间内容
strTmp@"<addkey='ConnectionString'value='server=localhost;database=数据库名;uid=sa;pwd=;pooling=true'/>";
获取“database=”与“;”号之间的字符串:database=(.*);database=([^;]*);;
MatchTitleMatchRegex.Match(strTmp,tmpStr,RegexOptions.IgnoreCase|RegexOptions.Multiline);
如下例子作语法参考用获取size的值,实际应用可能不会如此复杂><fontcolor='red'size=6>WebForm3</font><;
tmpStr<(w+s+w+[=]+[']+w+[']+s+[size=]+d)>RegexOptions.Multiline);
取出匹配项的值tmpStrTitleTitleMatch.Groups[1].Value;
替换掉HTML页中所有HTML标记Label1.TextRegex.Replace(Label1.Text.Trim(),<.+?>,0)">"")+*********].Value;
判断匹配正则表达式是否成功if(Regex.Match(tmpStr,0)">).Success)
{
操作}=====================End1========================
=====================Begin2========================webDocContent<ahref=http://www.xxx.xxx/college/pages/default.htmtarget=_blank>师资队伍</A>解释下面正则表达式:[s]表示匹配空格字符,"+"表示连接strPatterna[s]+href=(?<Link>[^s>]+)[^>]*>(?<Text>[^<]*)</a>获取链接显示的文字MatchCollectionMatchesRegex.Matches(webDocContent,strPattern,0)">RegexOptions.Compiled);
foreach(MatchNextMatchinMatches)
URLNextMatch.Groups[Link].Value.ToString().Trim();
URLTextText].Value.ToString().Trim();
Response.Write(URL****);
Response.Write(URLText);
}=====================End2========================
=====================Begin3========================strPageContent.Empty;
StreamReadersrPagenewStreamReader(e:save.txtgb2312));
strPageContentsrPage.ReadToEnd();
srPage.Close();
(/s)*表示0或多个空格符、回车符等,*表示比配0或多个。(.*?)表示除回车符外的所有信息MatchCollectionTitleMatchsRegex.Matches(strPageContent,0)"><tdwidth="85%"class="common_text">((/s)*(.*?)(/s)*(.*?)(/s)*(.*?)(/s)*(.*?)(/s)*)</td>RegexOptions.Multiline);
inttmpNum0循环正则表达式所获取的,满足表达式的内容集合TitleMatchs)
++tmpNum;
Label1.Text+=<br>****].Value;
}=====================End3========================