IsValid
Returns whether the current pattern compiles. Raises no error.
Syntax: object.IsValid
- object
- required An object expression that evaluates to a RegExp.
Returns a Boolean: True when Pattern compiles, False when it does not.
Remarks
The property compiles the pattern if it has not been compiled since Pattern or IgnoreCase last changed, and keeps the result. Nothing is raised when the compilation fails. For a pattern that fails, LastError holds the message and LastErrorNumber the number.
Check IsValid before Execute, Test, Replace or Split when the pattern comes from outside the program, because each of those raises the compile error.
Example
Dim re As RegExp
Set re = New RegExp
re.Pattern = "(\d+"
Debug.Print re.IsValid ' False
re.Pattern = "(\d+)"
Debug.Print re.IsValid ' True
See Also
- LastError property – the message of the compile error
- LastErrorNumber property – the number of the compile error
- Pattern property – the regular expression
- RegExp class – overview