Regular Expressions in LotusScript

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

March 2010

Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Archives

Powered by Movable Type 4.34-en

About this Entry

This page contains a single entry by philipz published on May 14, 2007 2:12 AM.

AS400 iSeries Access Port Number was the previous entry in this blog.

Notes Document Maintenance Tool is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.