This project enables LotusScript developers to use Regular Expressions in their code.
It does so by providing a script library with simple wrappers around Java classes that are invoked by LS2J.
The wrapper classes behave like native LotusScript classes. All the clumsiness of JNI declarations that comes with using LS2J is abstracted away from the user.
The SimpleRegexMatcher can determine whether a text matches a pattern.
In case of a match it gives you access to the matching part of the original text via its Match property.
The RegexMatcher combines java.util.regex.Pattern and java.util.regex.Matcher into one handy LotusScript wrapper to perform Regular Expression operations on text.
You can do repeated matches on the same string with the find() method to locate multiple occurrences of pattern matches, and you can access captured groups with the group() function. The replaceAll() and replaceFirst() methods let you replace matching parts with strings that may contain backreferences to captured parts of the original string.
In contrast to the SimpleRegexMatcher that is targeted to users new to the java.util.regex classes, RegexMatcher assumes a basic level of familiarity with the underlying Java classes.
Intended audience: LotusScript developers.
example code
Use "Regular Expressions"
' This example searches for an agent with licence to kill.
Dim Matcher1 As New SimpleRegexMatcher
If Matcher1.matches("James Bond is agent 007.", "\b00\d\b") Then
Print "found agent #" & Matcher1.Match ' prints "found agent #007"
End If
' Find name of someone who introduces himself in a James Bondish way.
' This example features capture groups and a backreference to the first capture group.
Dim Matcher2 As New RegexMatcher("My name is Presley. Elvis Presley.", "name is (\w+)\. (\w+) \1\.", 0)
If Matcher2.find() Then
Print Matcher2.group(2) & " " & Matcher2.group(1) ' prints "Elvis Presley"
End If
' Replace parts of the input using captured groups
Dim Matcher3 As New RegexMatcher("from 10:00 to 12:00", "from (\d\d:\d\d) to (\d\d:\d\d)", 0)
Print Matcher3.replaceAll("$1-$2") ' prints "10:00-12:00"