c# 正则获取html标签内容,正则表达式获取HTML标记中的内容(C#)

//=====================Begin1========================试验字符串stringstrTmp=.Empty;正则表达式tmpStr.Empty;取出指定HTML标记中的匹配项的值RegexOptions.IgnoreCase忽略大小写,RegexOptions.Multiline忽略多行显示,tmpStr="

([^"获取之间内容strTmp@"";获取“database=”与“;”号之间的字符串:database=(.*);database=([^;]*);;

MatchTitleMatchRegex.Match(strTmp,tmpStr,RegexOptions.IgnoreCase|RegexOptions.Multiline);如下例子作语法参考用获取size的值,实际应用可能不会如此复杂>WebForm3

tmpStrRegexOptions.Multiline);取出匹配项的值tmpStrTitleTitleMatch.Groups[1].Value;替换掉HTML页中所有HTML标记Label1.TextRegex.Replace(Label1.Text.Trim(),<.>,0)">"")+*********].Value;判断匹配正则表达式是否成功if(Regex.Match(tmpStr,0)">).Success){操作}=====================End1=============================================Begin2========================webDocContent师资队伍解释下面正则表达式:[s]表示匹配空格字符,"+"表示连接strPatterna[s]+href=(?[^s>]+)[^>]*>(?[^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)">((/s)*(.*?)(/s)*(.*?)(/s)*(.*?)(/s)*(.*?)(/s)*)RegexOptions.Multiline);inttmpNum0循环正则表达式所获取的,满足表达式的内容集合TitleMatchs)++tmpNum;

Label1.Text+=
****].Value;

}=====================End3========================