C#正则表达式将单词与点匹配 [英] C# Regex to match the word with dot
问题描述
敏捷的棕色狐狸跳过了懒狗"是英语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.
我需要获取字母表".正则表达式中的单词.在上面的文本中有3个实例.它不应该包括字母!".我刚刚用
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 个实例,包括字母表!".如何省略它并只获得字母表".
but this returns 4 instances including "alphabet!". How to omit this and get only "alphabet."
推荐答案
.
是正则表达式中的特殊字符,可以匹配任何内容.尝试逃避它:
.
is a special character in regex, that matches anything. Try escaping it:
MatchCollection match = Regex.Matches(entireText, @"alphabet.");
这篇关于C#正则表达式将单词与点匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!