本文介绍了C#正则表达式匹配单词与点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在regex中使用alphabet。字词在上述文本中有3个实例不是alphabet!我只是尝试regex与

I need to get the "alphabet." word in regex. In the above text there are 3 instances. It should not include "alphabet!". I just tried regex with

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

但这会返回4个实例,包括alphabet! 。

but this returns 4 instances including "alphabet!". How to omit this and get only "alphabet."

推荐答案

是regex中的一个特殊字符,尝试转义它:

. is a special character in regex, that matches anything. Try escaping it:

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

这篇关于C#正则表达式匹配单词与点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 07:40