Method: Execute for RegExp
- Updated2024-09-12
- 1 minute(s) read
Methods > Method: Execute for RegExp
Method: Execute for RegExp
Uses a regular expression to search in a character string and returns a collection that contains every match found in the character string.
Set oDispatch = Object.Execute(sourceString)
| Object | RegExp Object with this method |
| sourceString | String Specifies the character string you want to search through. |
| oDispatch | MatchCollection Returned object |
The following example checks whether the given character string contains the text pattern:
Function FindPattern(sPattern, sText) Dim RegExpression, Matches, Match, ResText Set RegExpression = CreateObject("VBScript.RegExp") RegExpression.Pattern = sPattern RegExpression.Global = True RegExpression.MultiLine = True Set Matches = RegExpression.Execute(sText) For Each Match in Matches ResText = ResText & "Match at " & Match.FirstIndex & vbCRLF Next FindPattern = ResText End Function