Platforms to show: All Mac Windows Linux Cross-Platform

Back to PCRE2MatchDataMBS class.

PCRE2MatchDataMBS.Constructor(code as PCRE2CodeMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Regular Expressions MBS RegEx Plugin 22.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new match data block for holding the result of a match.

The first argument points to a compiled pattern. The number of capturing parentheses within the pattern is used to compute the number of pairs of offsets that are required in the match data block. These form the "output vector" (ovector) within the match data block, and are used to identify the matched string and any captured substrings when matching with Match().

Use this to allocate a match data object for a specific code object.

See also:

PCRE2MatchDataMBS.Constructor(size as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Regular Expressions MBS RegEx Plugin 22.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new match data block, which is used for holding the result of a match.

The first argument specifies the number of pairs of offsets that are required. These form the "output vector" (ovector) within the match data block, and are used to identify the matched string and any captured substrings when matching with Match(). There is always one pair of offsets; if size is zero, it is treated as one.

Use this to allocate a match data object with a bigger size to use it with various pattern.

See also:

PCRE2MatchDataMBS.OffsetVector(index as Integer) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Regular Expressions MBS RegEx Plugin 22.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Queries the offset in the text for the match.
Example

Dim Compiler As New PCRE2CompilerMBS

// find numbers
compiler.Pattern = "(\d+)([$€£]?)"

Dim code As PCRE2CodeMBS = Compiler.Compile

// prepare reuable match object
Dim Match As New PCRE2MatchDataMBS(code)

// now run a match
Dim Text As String = "Täst 1234€ Case"
Dim n As Integer = code.Match(Text, match)

// get result found
Dim OVector0 As Integer = match.OffsetVector(2)
Dim OVector1 As Integer = match.OffsetVector(3)
Dim Len As Integer = OVector1 - OVector0
Dim pos As Integer = OVector0
Dim OwnSubString As String = Text.Middle(pos, Len)

Break

Values in number of characters and zero based, so maybe use Middle() function on strings.
Range is 0 to OffsetVectorCount*2-1.

OffsetVector(0) and OffsetVector(1) is the total match found.
OffsetVector(2) and OffsetVector(3) is the first captured sub string.
OffsetVector(4) and OffsetVector(5) is the second captured sub string.
...
OffsetVector(OffsetVectorCount*2-2) and OffsetVector(OffsetVectorCount*2-1) is the last captured sub string.

Some examples using this method:

PCRE2MatchDataMBS.OffsetVectors as Integer()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Regular Expressions MBS RegEx Plugin 22.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Queries array of vector values.

All the values in an array for faster access.

PCRE2MatchDataMBS.SubString(Index as Integer) as String

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Regular Expressions MBS RegEx Plugin 22.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Queries substring by index.
Example

Dim Compiler As New PCRE2CompilerMBS

// find numbers
compiler.Pattern = "(\d+)([$€£]?)"

Dim code As PCRE2CodeMBS = Compiler.Compile

// prepare reuable match object
Dim Match As New PCRE2MatchDataMBS(code)

// now run a match
Dim Text As String = "Täst 1234€ Case"
Dim n As Integer = code.Match(Text, match)

// get result found
Dim TotalSubString As String = match.SubString(0)
Dim SubString1 As String = match.SubString(1)
Dim SubString2 As String = match.SubString(2)

break // see debugger

See also:

PCRE2MatchDataMBS.SubString(Name as String) as String

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Regular Expressions MBS RegEx Plugin 22.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Queries substring by name.

See also:

PCRE2MatchDataMBS.SubStrings as String()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Regular Expressions MBS RegEx Plugin 22.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
A convenience function for extracting all the captured substrings after a pattern match.

The items on this page are in the following plugins: MBS RegEx Plugin.


The biggest plugin in space...