LastError
Returns the message of the error that compiling the current pattern raised.
Syntax: object.LastError
- object
- required An object expression that evaluates to a RegExp.
Returns a String: the description of the compile error, or an empty string when the pattern is valid.
Remarks
The property compiles the pattern if it has not been compiled since Pattern or IgnoreCase last changed. The compilation traps its error, so LastError raises nothing. The text is the Description of the error that the compilation raised; LastErrorNumber is its number.
Execute, Test, Replace and Split raise an error with this description when the pattern is invalid.
Example
Dim re As RegExp
Set re = New RegExp
re.Pattern = "(\d+)"
Debug.Print Len(re.LastError) ' 0
re.Pattern = "(\d+"
Debug.Print re.IsValid ' False
Debug.Print Len(re.LastError) > 0 ' True
On Error Resume Next
re.Test "123"
Debug.Print Err.Description = re.LastError ' True
See Also
- LastErrorNumber property – the number of the compile error
- IsValid property – whether the pattern compiles
- Pattern property – the regular expression
- RegExp class – overview