如字符串 111<#d#>222
要匹配到 <# #>中间的内容 
如上就是匹配到 d
正则该如何写?

解决方案 »

  1.   


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.IO;
    namespace sxLdfang
    {
        class Program
        {
            static void Main(string[] args)
            {
                string html = @"如字符串 111<#d#>222";
                string pattern = @"(?<=<#).*?(?=#>)";
                MatchCollection mc = Regex.Matches(html, pattern);
                foreach (Match m in mc)
                {
                    Console.WriteLine(m.Value);
                }
                Console.ReadKey();
            }
        }
    }
    运行结果:
    d