Appendix H. Regular Expressions

A regular expression is a pattern of text that consists of ordinary characters (such as letters a through z) and special characters that are known as metacharacters. The pattern is used to describe one or more strings to match when searching a body of text. The regular expression acts as a template for matching a character pattern to the string that is being searched for.

The following table contains the complete list of metacharacters and their behavior in the context of a regular expression.

Character

Description

\

Marks the next character as either a special character or a literal

^

Matches the beginning of input

$

Matches the end of input

*

Matches the preceding character zero or more times

+

Matches the preceding character one or more times

?

Matches the preceding character zero or one time

.

Matches any single character except a new-line character

(pattern)

Matches pattern and remembers the match. The matched substring can be retrieved from the resulting Matches collection, using Item [0]...[n]. To match the parentheses characters themselves, precede with slash — use "\" or "(\").

(?:pattern)

Matches pattern but does not capture the match, that is, it is a noncapturing match that is not stored for possible later use. This is useful for combining parts of a pattern with the "or" character (!). For example, "anomal (?:y ! ies)" is a more economical expression than "anomaly ! anomalies".

(?=pattern)

Positive lookahead matches the search string at any point where a string ...

Get VBScript Programmer's Reference, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.