How to Use Regular Expressions in C#

Waqas Anwar
22 December 2010
3472 Views

You have a regular expression and you want to match it with certain user input, you can use .NET built in Regex class available in System.Text.RegularExpressions as shown below:

The following expression will match only 5 numeric digits using IsMatch method of Regex class.

string pattern = @"^\d{5}$";
string input = @"12345";

bool result = Regex.IsMatch(input, pattern);