C#正则表达式将单词与点匹配

快速的棕色狐狸跳过懒狗“是一个英语pangram,字母!即包含所有字母表的短语。它已用于测试打字机字母表和计算机键盘,以及其他涉及英文字母中所有字母的申请。

我需要得到“字母表”。 正则表达式中的单词。 在上面的文本中有3个实例。 它不应该包括“字母!”。 我刚试过正则表达式

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

但这会返回4个实例,包括“alphabet!”。 如何省略这一点,只获得“字母表”。

. 是正则表达式中的一个特殊字符,可以匹配任何内容。 尝试逃避它:

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

. 是正则表达式中的特殊字符。 你需要先用斜杠来逃避它:

 Regex.Matches(entireText, "alphabet\\.") 

斜杠最终是双倍的,因为\字符串中的\必须依次用另一个斜杠转义。

“” 在正则表达式中有特殊含义。 逃离它以匹配期间

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

编辑:

完整代码,给出预期结果:

  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); } }