Thursday, March 24, 2011

.NET interview questions :- What are Regex / regular expressions ?

Regex or regular expression helps us 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 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.
View our 21 important .NET interview questions and answers from .NET Interview questions

No comments: