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

标签 c# regex vb.net c#-4.0 c#-3.0

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.

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

尝试了正则表达式
 MatchCollection match = Regex.Matches(entireText, "alphabet."); 

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

最佳答案

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

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

关于C# 正则表达式将单词与点匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5696921/

相关文章:

c# - ASP.Net MVC 5 中的 Cookie

c# - 异常后停止函数

.net - 如何根据 FieldName 显示数据 - Access

c# - 如果函数包含同名的局部函数,如何递归调用函数?

c# - 在 Nhibernate 中执行简单的过程调用

java - 在Processing中正确读取IRC数据

javascript - JS - 通过正则表达式将字符串拆分为子字符串

regex - 以正则表达式匹配小时/分钟/秒-更好的方法?

vb.net - 我可以更改 .net 中 try catch block 的自动填充吗?

.net - 异常处理最佳实践