C#正则表达式匹配单词与点 [英] C# Regex to match the word with dot

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

问题描述


快速棕色狐狸跳过
懒狗是一个英语
pangram,字母!也就是一个短语
,包含所有的字母
字母表,用于测试
打字机字母表和电脑
键盘,在其他应用程序中
涉及
中的所有字母英语字母表。

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.

我需要在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#正则表达式匹配单词与点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆