1. Home
  2. Computing & Technology
  3. Visual Basic

Using Regular Expressions in ASP.NET

By , About.com Guide

4 of 7

How a RegEx Works

Regexes match text, character by character from left to right. (Although .NET can also do right to left matching!) Most letters and characters will simply match themselves. For example, the regex character "<" will match the string character "<". But there is also a list of "metacharacters" that are treated differently. Here's the comlete list:

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

The most important metacharacter is probably the backslash, "\". The backslash can be followed by various characters to signal various special sequences and to escape all the metacharacters so you can still match them in patterns. For example, if you need to match a "?", you can precede it with a backslash to remove the special meaning: \?. In our example regex, "\w" will match any alphanumeric character and it's equivalent to the class: [a-zA-Z0-9_]. In words, "lower case a to z, upper case A to Z, 0 to 9 and underscore".

Explore Visual Basic
By Category
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Learn VB.NET
  5. Learn ASP.NET
  6. Using Regular Expressions in ASP.NET

©2009 About.com, a part of The New York Times Company.

All rights reserved.