VBA Microsoft VBScript Regular Expressions Library

The VBScript_RegExp_55 library contains classes for working with Regular Expressions.

Classes

The VBScript_RegExp_55 library contains four classes that assist with working with regular expressions: RexExp, Match, MatchCollection, and SubMatches.

RegExp

The RegExp class is the top-level object for working with regular expressions. The RegExp class is used to control settings for how a regular expression will be used to evaluate a string. The Execute, Replace, and Test methods of the RegExp class are used to evaluate text using a given pattern.

Member Description
Global If True, all matches will be returned. If False, only the first match will be returned.
IgnoreCase If True, matches will be case-insensitive. If False, matches will be case-sensitive.
Multiline If True, ^ will match the beginning of a line after a new line character and $ will match the end of a line before a new line character. If False, ^ will match the beginning of the entire string and $ will match the end of the entire string.
Pattern The regular expression pattern.
Execute Returns a MatchCollection. Uses the Pattern property to search the sourceString.
Replace Replaces matches with replaceVar and returns the String with replacements made.
Test Returns True if Pattern finds a match in sourceString, otherwise returns False.

Match

The Match class represents a single match within a string of text given a regex pattern.

Member Description
FirstIndex Returns the index of the first character of the match in the search string.
Length Returns the length of the match string.
SubMatches Returns a SubMatches Object.
Value Default member. Returns the matched text.

MatchCollection

The MatchCollection class represents a collection of matches within a string of text given a regex pattern.

Member Description
Count Returns count of Match objects in the collection.
Item Default member. Returns a Match object.

SubMatches

The SubMatches class represents sub matches of a regex pattern within a string that matches the pattern.

Member Description
Count Returns count of sub matches.
Item Returns match at a specified index.