Skip to content

MatchAllOffsets - cRegEx

Finds all matches and returns their start and end offsets in a two-dimensional array

Type: Function
Return Data Type: Integer[][]

Parameters

Parameter Type Description
sSubject String The host string to run the regular expression on
bGroups Boolean If True. the array will contain both the full matches and the individual group matches

Syntax

Function MatchAllOffsets String sSubject Boolean bGroups Returns Integer[][]

Call Example

Get MatchAllOffsets sSubject bGroups to Integer[][]Variable

Description

Finds all matches and returns their start and end offsets in a two-dimensional array.

Returns a two dimensional array with the start and end offsets of all matches found in the subject string. The offset positions are 1 based and position [0] is the start offset where [1] is the end offset. If bGroups is True, the array will contain both the full matches and the individual group matches; if bGroups is False, the array will contain only the full matches.

Sample

The example below shows how to find the offsets of matches in the subject string. The output of the sample should be "fun" and "lock".

Handle hoRegEx 
Integer[][] aOffsets 
String sSubject 

Get Create (RefClass(cRegEx)) to hoRegEx 
Set psExpression of hoRegEx to "fun|luck" 

Move "This is no fun! This is luck!" to sSubject 
Get MatchAllOffsets of hoRegEx sSubject False to aOffsets 

Showln (Mid(sSubject, aOffsets[0][1] - aOffsets[0][0], aOffsets[0][0])) 
Showln (Mid(sSubject, aOffsets[1][1] - aOffsets[1][0], aOffsets[1][0])) 

Send Destroy of hoRegEx

Return Value

Two-dimensional array of the full matches (if bGroups is True) and start and end offsets of all matches.