How to Use Regular Expressions in C#


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

 

 

About author


User avatar

Waqas Anwar

Founder of EzzyLearning.com, Senior Consultant, Microsoft .NET and Web Technologies

Comments