<html>
<title>任何字符,无内容也要提取</title>
<html>如何提取<title></title>之间的内容?

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string str = @"<html>
    <title>任何字符,无内容也要提取111</title>
    <html>如何提取<title>2222</title>之间的内容?";
                Regex re = new Regex(@"(?i)(?<=<title>).*?(?=</title>)");
                MatchCollection mc = re.Matches(str);
                foreach (Match item in mc)
                {
                    Console.WriteLine(item.Value);
                }
               
            }       
        }
    }
      

  2.   

    Console.WriteLine(Regex.Match(html,"(?i)(?<=<title>).*(?=</title>)").Value);
      

  3.   


    string s = "<title>任何字符,无内容也要提取</title>";
                Match m = Regex.Match(s, @"<title.*?>(.*?)</title>", RegexOptions.IgnoreCase);
                if (m.Groups.Count >= 2)
                {
                    s = m.Groups[1].Value;
                }
    //s就是要最后的结果