Using Regular Expression for pattern search and regular expression validator

   Regular expression is the single or group of special symbols to construct pattern to find data from the contents and allow or restrict the input data to the system. Regular Expression just like separate computer language. .Net has this feature to reduce the code to achieve above functionalities. System.Text.RegularExpressions gives this feature.






Beginning of input text


A, Text started with A (Represent to find the first word in the multiline text.)


End of the input text


Z, Text ended with Z (Represent to find the last word in the multiline text.)


Any single character except new line character (\n).


Line, Lime


Preceding character may be repeated 0 or more times.


ie, ise, isse, issse, isssse …


Preceding character may be repeated 1 or more times.


ise, isse, issse, isssse …


Preceding character may be repeated 0 or 1 time.


ie, ise


Any whitespace character


[Space]ar, [new line\n]ar [tab\t]ar


Any character other than whitespace character.


Ear, jar, war, var ..


Any word boundary (either beginning or end) characters specified


Nation, solution, addition …


Any word with specified characters in any position except (boundary) beginning and end.


Success, access


Decimal characters


3 digit


Non -Decimal characters



  • Regularexpression uses to validate the input data in the specific format. In .Net web pages validate the input text using regular expression validator control (System.Web.UI.WebControls.RegularExpressionValidator).






US telephone

((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}

(656) 555-7419

Singapore telephone with country code

((\(\d{2}\) ?))?\d{8}

(65) 65557419

Web address

http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?

Numerical input only



Non numerical input



  • uses to search the words in specific pattern from the contents.

using System;

using System.Text.RegularExpressions;

namespace RegularExpression


class Program


public static string input = @"I have been in software industry

since 1999 holding various roles and responsibilities as developer,

tester and support team member from small scale industry to industry

giant. And having experience and expertise with Microsoft technologies

such as VB, SQL Server, C#.Net, Vb.NET, ASP.NET, ADO.NET, Crystal report

and Oracle. And involved in requirement study, design, development,

testing, implementation, documentation , training and support in my carrier.";

static void Main(string[] args)


//Some example for the pattern to search the word from the input text

//@"\S*\Bcr\S*" Microsoft

//@"\bcr\S*" Crystal

//@"\S*\bvb\S*" Vb,

//@"\S*Net\b*" C#.Net, VB.Net, ASP.Net,

//@"\S*ier.$" carrier. (last word in the input string)

//@"^i\S*" I (First word in the input string)

MatchCollection Matches = findTheMatches(@"^i\S*");

foreach (Match match in Matches)







static MatchCollection findTheMatches(string Pattern)


return Regex.Matches(input, Pattern, RegexOptions.IgnoreCase);




  • delete the repeated word from the contents using specific pattern

  • convert the character case in the word using specific pattern.

  • make sure the character case in the word.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s