Thursday, June 9, 2011

.NET interview questions :- What are regular expressions in .NET ?

Do view our 15 minutes video on regex as below



C# Regex or regular expression helps us to describe complex patterns in texts. Once you have described these patterns you can use them to do searching, replacing, extracting and modifying text data.

Below is a simple sample of how to implement regex . The first step is to import the namespace for regular expressions.

using System.Text.RegularExpressions;

The next thing is to create the regex object with the pattern. The below pattern specifies to search for alphabets between a-z with 10 length.

Regex obj = new Regex(“[a-z]{10}”);

Finally search the pattern over the data to see if there are matches. In case the pattern is matching the ‘IsMatch’ will return true.

MessageBox.Show(obj.IsMatch(“shivkoirala”).ToString());

Please click here to see more C# interview questions and answers

Regards,

Visit Authors blog for more Dotnet and C# interview questions

No comments: