Pattern Property
Defines the Regular Expression Pattern.
Property Usage:
Syntax: Object.Pattern = "<PATTERN STRING>"
Examples:
regExpObj.Pattern
= "^\d{4}_\d{6}$" ' Match strings in the format
1234_567890
regExpObj.Pattern
= "\b\d{2}/\d{2}/\d{4}\b" 'Matches dates in the
MM/DD/YYYY format
Example:
Dim regex, inputText
Set regex = CreateObject("VBScript.RegExp")
regex.Pattern = "^\d{4}_\d{6}$" ' Match strings in the format 1234_567890
inputText = "1234_567890"
' Check if the inputText matches the pattern
If regex.Test(inputText) Then
'Valid Format Related Coding
Else
'Invalid format Related Coding
End If
In above code, the pattern ^\d{4}_\d{6}$ ensures that inputText must be exactly in the form of 4 digits followed by an underscore (_) and 6 digits at the end. If the inputText matches the pattern, it will trigger Valid format section code flow. Otherwise, it will fall into Invalid format related code flow.