Name

RegExp Object

Description

The RegExp object provides support for regular expression matching—for the ability to search strings for substrings matching general or specific patterns.

In order to conduct a pattern search, you must first instantiate the regular expression object, with code like the following:

Dim oRegExp             ' Instance of RegExp object 
Set oRegExp = New RegExp

To conduct a search using the RegExp object, do the following:

  • Determine whether the search should be case sensitive or not.

  • Determine whether all instances or just the first instance of the substring should be returned.

  • Supply the pattern string that you want to find.

  • Provide a string that the RegExp object is to search.

The RegExp object allows you to search for a substring that matches your pattern string in any of three ways:

  • You can determine whether a pattern match is found in the string.

  • You can return one or all of the occurrences of the matching substrings. In this case, results are returned in Match objects within the Matches collection.

  • You can replace all substrings matching the pattern string with another string.

Properties

The RegExp object supports the three properties shown in the following table. Each is documented in depth in its own section in the Language Reference.

Property Name

Description

Global

Indicates whether to search for all occurrences of the pattern string or just for the first one

IgnoreCase

Indicates whether or not the pattern search is case-sensitive

Pattern

Indicates the pattern ...

Get VBScript in a Nutshell 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.