class TestRegularExpressions
{
    static void Main()
    {
        string[] sentences = 
        {
            "cow over the moon",
            "Betsy the Cow",
            "cowering in the corner",
            "no match here"
        };

        string sPattern = "cow";

        foreach (string s in sentences)
        {
            System.Console.Write("{0,24}", s);

            if (System.Text.RegularExpressions.Regex.IsMatch(s, sPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
            {
                System.Console.WriteLine(" (match for '{0}' found)", sPattern);
            }
            else
            {
                System.Console.WriteLine();
            }
        }
    }
}
 
 

輸出

       cow over the moon  (match for 'cow' found)
       Betsy the Cow  (match for 'cow' found)
       cowering in the corner  (match for 'cow' found)
       no match here
創作者介紹
創作者 遊戲人生 人生遊戲 的頭像
createps

遊戲人生 人生遊戲

createps 發表在 痞客邦 留言(0) 人氣( 203 )