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
Var Compiler As New PCRE2CompilerMBS

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

Var code As PCRE2CodeMBS = Compiler.Compile

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

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

// get result found
Var OVector0 As Integer = match.OffsetVector(2)
Var OVector1 As Integer = match.OffsetVector(3)
Var Len As Integer = OVector1 - OVector0
Var pos As Integer = OVector0
Var 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
Var Compiler As New PCRE2CompilerMBS

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

Var code As PCRE2CodeMBS = Compiler.Compile

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

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

// get result found
Var TotalSubString As String = match.SubString(0)
Var SubString1 As String = match.SubString(1)
Var 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.
Example
Var Compiler As New PCRE2CompilerMBS

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

Var code As PCRE2CodeMBS = Compiler.Compile

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

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

// show matched text
Var subStrings() As String = match.SubStrings
Break

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


The biggest plugin in space...