Method: Test for RegExp
- Updated2024-09-12
- 1 minute(s) read
Methods > Method: Test for RegExp
Method: Test for RegExp
Searches, with a regular expression, in a character string an returns a Boolean value that specifies whether the character string contains the text pattern.
bTest = Object.Test(sourceString)
Object | RegExp Object with this method |
sourceString | String Specifies the character string you want to search through. |
bTest | Boolean The method Test returns TRUE if the character string contains a text pattern. Otherwise the method returns FALSE. |
The following example checks whether a given character string contains special characters:
Function FindSpecChar(sText) Dim RegExpression Set RegExpression = CreateObject("VBScript.RegExp") RegExpression.Global = True RegExpression.MultiLine = True RegExpression.Pattern = "[^0-9a-zA-Z]" If RegExpression.Test(sText) Then FindSpecChar = "Pattern exists" Else FindSpecChar = "Pattern doesn't exist" End If End Function