繁体   English   中英

如何在C#中使用自定义正则表达式?

[英]How can use custom regex in c#?

class Program
{
    private static void showMatch(string text, string expr)
    {
        Console.WriteLine("The Expression: " + expr);
        MatchCollection mc = Regex.Matches(text, expr);

        foreach (Match m in mc)
        {
            Console.WriteLine(m);
        }
    }
    static void Main(string[] args)
    {
        string str = "A Thousand Splendid Suns";

        string pattern = @"[>][@\/" - &',.\w+ -]+[<]";
        Console.WriteLine("Matching words that start with 'S': ");
        showMatch(str, pattern);      
        Console.ReadKey();
    }
}
   string pattern = @"[>][@\/"" - &',.\w+ -]+[<]";

双引号会为您逃脱。 这条线现在有效

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM