Thursday, May 15, 2008

Regular Expressions and C#, .NET

This Article explores the concept of Regular Expressions in the context of C#, .NET support for Regular
Expressions, Meta-characters and their Description, Character Escapes, Substitutions, Character Classes, Regular Expression Options and Atomic Zero-Width Assertions.

What are regular expressions?
Regular expressions are Patterns that can be used to match strings. You can call it a formula for matching strings that follow some pattern. Regular expression(s) can be considered as a Language, which is designed to manipulate text. You can then ask questions such as
“Does the given string match the pattern?”, or “Does the given string contain characters that match a pattern?”. Regular Expressions may be used to find one or more occurrences of a pattern of characters within a string. You may choose to replace it with some other characters or perform some other tasks based on the results obtained. These patterns of characters can be simple or very complex. Regular Expressions generally comprises of two types of characters –
1) Literal or Normal Characters such as “abcd123” 2) Special Characters that have a special meaning such as “.” Or “$” or “^”
Due to the special characters Regular Expressions form a very powerful means of manipulating strings and text.

.NET support for Regular Expressions:
.Net provides an extensive set of Regular expressions which you could use to create, modify or compare strings. They can be classified as follows –
a) Character Escapes b) Substitutions c) Character Classes d) Regular Expression Options e) Atomic Zero-Width Assertions f) Quantifiers g) Grouping Constructs h) Backreference Constructs i) Alternation Constructs j) Miscellaneous Constructs

No comments: