Reqular experssion RegEx, C# , asp.net , vb.net

Regular expression:

Regular Expression is a great way to manipulate strings for example matching, finding, validating Data, Specailly string manipulaion becames handy while we use reqular expression.

We can use Regular expression on both Serer and client side. We do use it with asp.net validation controls.

Charcther matching:

. ^ $ * + ? { [ ] \ | ( )

\d Matches any decimal digit. This is equivalent to the class [0-9].

\D Matches any non-digit character. This is equivalent to the class

[^0-9].

\s Matches any whitespace character; this is equivalent to the class

[ \t\n\r\f\v].

\S Matches any non-whitespace character; this is equivalent to the class [^ \t\n\r\f\v].

\w Matches any alphanumeric character; this is equivalent to the class [a-zA-Z0-9_].

\W Matches any non-alphanumeric character; this is equivalent to the class [^a-zA-Z0-9_].

Period or dot “.” When used in Reqular expression could be any charcter other than new line characters.

[1234]Cricket will return 1,2,3 or 4 if they occur before Cricket OR

[1-4]Cricket

[a-m] ranges between a-m and A-M

“\” backslash and “?” Question Mark

(?) is used to find occurrence of previous character

(\) is use dto find exact occurance of pervious character

4{3}Cricket will return 444Cricket

“^” carrot ^cricket if cricket are first 7 charcters

“$” dollar $crikct if cricket are 7 last charcters

“\w+” is a word occurrence

(*) estrick means all

To check decimal or dot use \.?

?# is used to write commetns inside regular expression

To remove html Tags use “< (.+?)>”

If Input is a valid number or not:

To check if an input provided is a valid number use following reuglar expression

“(^([0-9]*|\d*\d{1}?\d*)$)”

Understating above expression will help how it works.

I Wan to share this post:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • kick.ie
  • Live
  • MyShare
  • IndianPad
  • Reddit
  • StumbleUpon
  • Technorati
  • YahooMyWeb
  • DotNetKicks
  • DZone
  • TwitThis

If you have to provide some services to all users of your website then….


If you have to provide some data or services to all of your web users then best option is to put those data values into applicaiton object. This process will make your application very fast.

You can use Global.asax  file and can use  following event.  Following code first puts value into a hashtable and then this hash table is added to the applicaiton object of Asp.net. C# code.protected void Application_BeginRequest(Object sender, EventArgs e){

Hashtable userHash = new Hashtable();

foreach (User user in userDetails)
{
userHash.Add(user.Id, user.UserName);
}

Application.Add(cachekey, userHash);

}


I Wan to share this post:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • kick.ie
  • Live
  • MyShare
  • IndianPad
  • Reddit
  • StumbleUpon
  • Technorati
  • YahooMyWeb
  • DotNetKicks
  • DZone
  • TwitThis