asp.net.ph

Skip Navigation LinksHome > Getting Started > ASP.NET Base Types > Regular Expressions > Regular Expressions as a Language

Regular Expressions as a Language

Getting Started   ASP.NET Base Types   Regular Expressions


The regular expression language is designed and optimized to manipulate text.

The language comprises two basic character types: literal ( normal ) text characters and metacharacters. It is the set of metacharacters that gives regular expressions their processing power.

You are probably familiar with the ? and * metacharacters used with the DOS file system to represent any single character or group of characters.

The DOS file command COPY *.DOC A: commands the file system to copy any file with a .DOC file name extension to the disk in drive A. The metacharacter * stands for any file name before the file name extension .DOC.

Regular expressions extend this basic idea many times over, providing a large set of metacharacters that make it possible to describe very complex text-matching expressions with relatively few characters.

For example, the regular expression \s2000, when applied to a body of text, matches all occurrences of the string “2000” that are preceded by any white-space character, such as a space or a tab.

NOTE: If you are using C++, C#, or JScript, special escaped characters such as \s, must be preceded by an additional backslash ( for example, \\s2000 ) to signal that the backslash in the escaped character is a literal character.

Otherwise, the regular expression engine treats the backslash and the s in \s as two separate operators.

You do not have to add the backslash if you are using Visual Basic .NET. If you are using C#, you can use C# literal strings, which are prefixed with @ and disable escaping. For example, @"\s2000"

Regular expressions can also perform more complex searches. For example, the regular expression ( ?<char>\w ) \k<char>, using named groups and backreferencing ( explained in the following sections ), searches for adjacent paired characters.

When applied to the string “I’ll have a double tall latte”, it finds matches in the words “I’ll”, “tall”, and “latte”. ( For details on this regular expression, see Backreferences. )

The following sections detail the set of metacharacters that define the .NET Framework regular expression language and show how to use the regular expression classes to implement regular expressions in your applications.



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note