C# Regex to match the word with dot

pili picture pili · Apr 18, 2011 · Viewed 47.9k times · Source

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.

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."); 

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

Answer

Håvard picture Håvard · Apr 18, 2011

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

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