From Lotus Sandbox, by David M Phillips.
This regular expressions in LotusScript using the VBScript RegExp object.
Example:
Dim re As New RegExp
' Pattern matching defaults to case sensitive.
Dim test As Boolean
test = re.Test ("ABC", "b")
Msgbox "'ABC' contains 'b' (case sensitive) = " & test
re.IgnoreCase = True
test = re.Test ("ABC", "b")
Msgbox "'ABC' contains 'b' (case insensitive) = " & test
' Match returns success indication.
test = re.Match ("xyz", "a")
Msgbox "'xyz' has a match for 'a' = " & test
' Global defaults to False; = return first match only.
Dim count As Integer
test = re.Match ("them these theirs", "e")
' Match returns successful matches as a collection property.
count = re.matches.count
Msgbox "'them these theirs' with Global = false matches 'e' " & count & " time."
' Global defaults to True; = return All match.
re.Global = True
test = re.Match ("them these theirs", "e")
' Match returns successful matches as a collection property.
count = re.matches.count
Msgbox "'them these theirs' with Global = false matches 'e' " & count & " time."
re.Global = True
test = re.Match ("them these theirs", "the[a-z]+")
Dim position As Integer
Dim length As Integer
Dim s As String
Dim msg As String
Forall m In re.matches
position = m.FirstIndex ' zero-based
length = m.Length
s = m.Value
msg = msg & "Match at position " & position & ". " & length & " character string = " & s & Chr (10)
End Forall
Msgbox msg
' Replaces returns source string with any successful replacement.
s = re.Replaces (s, "([a-z]*)\W(\w*)\s(\S*)", "$3 $2 $1")
Msgbox "Change 'them these theirs' to '" & s & "'."
But, also could use Java, "java.util.regex" package.
Script Library:
import java.util.regex.*;
public class regex {
public boolean check(String patten, String input){
return Pattern.matches(patten, input);
}
}
Sub Click(Source As Button)
Dim js As JAVASESSION
Dim regexClass As JAVACLASS
Dim regexObject As JavaObject
Set js = New JAVASESSION
Set regexClass = js.GetClass("regex")
Set regexObject = regexClass.CreateObject
Msgbox regexObject.check("^[A-Za-z]+$", "00")
End Sub
For more information, see the following:
* VBScript RegExp object properties and methods
Sun Java tutorial: Regular Expressions