簡體   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