CATPackageMethodRegex Functions

These functions help you create and evaluate regular expressions in EKL.

This page discusses:

Regex

Signature

Regex(regexString : String) : Regex

Arguments

NameInput/OutputRequired?TypeComment
regexStringInString-

ReturnType

Regex

Regex.Group()

Returns a capture group. Group(0) is the full capture string.

Signature

Regex.Group(indexGroup : Integer) : String

Arguments

NameInput/OutputRequired?TypeComment
indexGroupInInteger-

ReturnType

String

Example

let regex(Regex)
let b(Boolean)
let ss(String)
let i(Integer)
regex = Regex("+(/d{2})/s(/d{3})-(/d{3})-(/d{4})")
b = regex -> Search("Tel : +33 111-777-9999")
i= 0
for i while i< regex->GroupCount()
{
	Notify("Group # : #", i, regex ->Group(i))	
}
//The result is:
Group 0:  +33 111-777-9999
Group 1: 33
Group 2: 111
Group 3: 777
Group 4: 9999

Regex.GroupCount()

Returns the number of matched groups. It includes the entire regular expression. Note that the groups are regular expressions that correspond to the string in parenthesis in the string that defines the regular expression.

Signature

Regex.GroupCount() : Integer

ReturnType

Integer

Example

let regex(Regex)
let i(Integer)
regex = Regex("+(/d{2})/s(/d{3})-(/d{3})-(/d{4})")
i= regex->GroupCount()
// i == 5 because we have 4 groups plus one for the entire regular expression.

Regex.Match()

Returns True if the input iText text matches the regular expression and False if it is not the case. Note that the whole text needs to match the regular expression.

Signature

Regex.Match(stringToMatch : String) : Boolean

Arguments

NameInput/OutputRequired?TypeComment
stringToMatchInString-

ReturnType

Boolean

Example

let regex(Regex)
let b(Boolean)
regex = Regex("+(/d{2})/s(/d{3})-(/d{3})-(/d{4})")

//Test Match 
b = regex -> Match("Tel : +33 111-777-9999")
// b == False

b = regex -> Match("+33 111-777-9999")
//b == True

Regex.Replace()

Allows to substitute the part of the input text matching a regular expression by another text.

Signature

Regex.Replace(stringToReplace : String, stringToSearch : String, nbMaxSubstitutions : Integer) : String

Arguments

NameInput/OutputRequired?TypeComment
stringToReplaceInString Input text to substitute (may contains \\1, \\2, ..., \\9 to retrieve capture groups).
stringToSearchInString Input text to search.
nbMaxSubstitutionsInInteger Number of max substitutions. Any value greater than -1 is authorized and -1 means all matches will be replaced.

ReturnType

String

Example

let regex(Regex)
let b(Boolean)
let reBackRef(String)
let ss(String)
regex = Regex("+(/d{2})/s(/d{3})-(/d{3})-(/d{4})")
reBackRef = "\\2::\\3::\\4"
ss = regex->Replace(reBackRef,"+33 111-777-9999",-1)
	// ss == “111::777::9999”

Regex.Search()

Returns True if part of the iText input text matches the regular expression and False if not.

Signature

Regex.Search(stringToSearch : String) : Boolean

Arguments

NameInput/OutputRequired?TypeComment
stringToSearchInString--

ReturnType

Boolean

Example

let regex(Regex)
let b(Boolean)
regex = Regex("+(/d{2})/s(/d{3})-(/d{3})-(/d{4})")

//Test Search
b = regex -> Search("Tel : +33 111-777-9999")
//b == True

b = regex -> Search("Tel : +33 0111-777-9999")
//b == False