Regular Expressions in Notes (Lotusscript)

Today I needed to use regular expressions (a.k.a. regexp) in a Lotus Notes application. I just wanted to check if the user entered a claim number (in the format “nnXXXXXnnnnn”, e.g. 12RICTX12345) in a field. A quick online search found a blog entry with some code using the VBScript object available in Windows, and I adapted it for my application.
Just in case someone need this, I am posting the code below. I am not taking credit for the code, I found it on Giles Hinton´s blog and just adapted it a little bit.

I also found information about using LS2J and Java to handle regular expression in Notes, which should be platform independent, not restricted to just Windows. Since all our users are on Windows (either directly or through Citrix), I could use the quick method below. But I would probably use the script library posted on OpenNTF for more serious code.


Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim regex As Variant
Dim pattern As String
Dim result As String
Dim match As Boolean

'*** Define pattern and get text value to check for match
pattern = |b([0-9]{2}[a-zA-Z]{5}[0-9]{5})b|
Set uidoc = ws.CurrentDocument
subject = uidoc.FieldGetText("ShortDescription")
'*** Create RegExp object
Set regex = CreateObject("VBScript.Regexp")
regex.Global = True
regex.IgnoreCase = True
regex.Pattern = pattern
'*** Test for match of pattern in text
match = regex.Test(subject)
If match = True Then
    Msgbox "Claim number was found in the field."
End If

Leave a Reply