<img src="http://himg.mangocity.com/img/tese3_on.jpg" width="15" height="15" title="有免费健身设施" align="absmiddle"/>
我想用正则表达式取出title里的内容请问呢应该怎么来做的?知道的告诉下谢谢!

解决方案 »

  1.   

    <img.*title="([^/].*?)/>
    取分组1
      

  2.   


    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);
    }
    }/*
    结果:有免费健身设施
    */
      

  3.   

            string str = @"<img src=""http://himg.mangocity.com/img/tese3_on.jpg"" width=""15"" height=""15"" title=""有免费健身设施"" align=""absmiddle""/>";
            Console.WriteLine(Regex.Match(str,@"<img.*?title=""([^""]+)""[^/]+/>").Groups[1].Value);
      

  4.   


    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);
      

  5.   

    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);
        }
    {