C# Regex to match the word with dot

后端 未结 3 1786
名媛妹妹
名媛妹妹 2020-12-01 12:10

The quick brown fox jumps over the lazy dog\" is an English-language pangram, alphabet! that is, a phrase that contains all of the letters of the alph

3条回答
  •  鱼传尺愫
    2020-12-01 12:42

    "." has special meaning in Regular expressions. Escape it to match the period

    MatchCollection match = Regex.Matches(entireText, @"alphabet\.");
    

    Edit:

    Full code, giving expected result:

            string entireText = @"The quick brown fox jumps over the lazy dog is an English-language pangram, alphabet! that is, a phrase that contains all of the letters of the alphabet. It has been used to test typewriters alphabet. and computer keyboards, and in other applications involving all of the letters in the English alphabet.";
            MatchCollection matches = Regex.Matches(entireText, @"alphabet\.");
            foreach (Match match in matches)
            {
                foreach (Group group in match.Groups)
                {
                    Console.WriteLine(group);
                }
            }
    

提交回复
热议问题