string input = "<img src=\"http://himg.mangocity.com/img/tese3_on.jpg\" width=\"15\" height=\"15\" title=\"fdssd有免费健身设施\" align=\"absmiddle\"/>"; Regex reg = new Regex(@"(?is)<img[^>]*?title=(['""]?)(?<title>[^'""\s]+)\1[^>]*?>"); Match m = reg.Match(input); Response.Write(m.Groups["title"].Value);
Regex re = new Regex(@"title="(.*?)"",RegexOptions.None); MatchCollectionre.Matches mc = new MatchCollectionre.Matches("Text"); foreach (Match match0 in mc) //搜索所有父匹配 { MessageBox.Show(match0.Value); foreach (Match match1 in match父.Groups) //搜索所有子匹配 { MessageBox.Show(match1.Value); } {
取分组1
void Main()
{
string html=@"<img src=""http://himg.mangocity.com/img/tese3_on.jpg"" width=""15"" height=""15"" title=""有免费健身设施"" align=""absmiddle""/>";
Match m = Regex.Match(html,@"(?i)<img.*title=""([^""].*?)""");
if(m.Success)
{
Console.WriteLine(m.Groups[1].Value);
}
}/*
结果:有免费健身设施
*/
Console.WriteLine(Regex.Match(str,@"<img.*?title=""([^""]+)""[^/]+/>").Groups[1].Value);
string input = "<img src=\"http://himg.mangocity.com/img/tese3_on.jpg\" width=\"15\" height=\"15\" title=\"fdssd有免费健身设施\" align=\"absmiddle\"/>";
Regex reg = new Regex(@"(?is)<img[^>]*?title=(['""]?)(?<title>[^'""\s]+)\1[^>]*?>");
Match m = reg.Match(input);
Response.Write(m.Groups["title"].Value);
MatchCollectionre.Matches mc = new MatchCollectionre.Matches("Text");
foreach (Match match0 in mc) //搜索所有父匹配
{
MessageBox.Show(match0.Value);
foreach (Match match1 in match父.Groups) //搜索所有子匹配
{
MessageBox.Show(match1.Value);
}
{