Platforms to show: All Mac Windows Linux Cross-Platform

PCRE2CodeMBS.Constructor private
Type Topic Plugin Version macOS Windows Linux iOS Targets
method Regular Expressions MBS RegEx Plugin 22.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Function: The private constructor.
PCRE2CodeMBS.Copy(withTables as boolean = false) as PCRE2CodeMBS
Type Topic Plugin Version macOS Windows Linux iOS Targets
method Regular Expressions MBS RegEx Plugin 22.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Function: Makes a copy of the memory used for a compiled pattern, excluding any memory used by the JIT compiler.
Notes: Without a subsequent call to JITCompile(), the copy can be used only for non-JIT matching. The pointer to the character tables is copied, not the tables themselves (unless withTables is true).
PCRE2CodeMBS.Infos as PCRE2CodeInfoMBS()
Type Topic Plugin Version macOS Windows Linux iOS Targets
method Regular Expressions MBS RegEx Plugin 22.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Function: Enumerate callouts in a compiled pattern.
Example:

Dim Compiler As New PCRE2CompilerMBS

// pattern with callout
compiler.Pattern = "A(?C3)B"

Dim code As PCRE2CodeMBS = Compiler.Compile
Dim codeInfo() As PCRE2CodeInfoMBS = code.Infos

break // look into debugger
Notes: Useful to debug the pattern.
PCRE2CodeMBS.JITCompile(Flags as Integer = 1)
Type Topic Plugin Version macOS Windows Linux iOS Targets
method Regular Expressions MBS RegEx Plugin 22.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Function: Requests JIT compilation.
Notes: If the just-in-time compiler is available, further processes a compiled pattern into machine code that executes much faster than the Match() interpretive matching function.

Some examples using this method:

PCRE2CodeMBS.Match(Text as String, matchData as PCRE2MatchDataMBS, StartOffsetCharacters as Integer = 0, MatchContext as PCRE2MatchContextMBS = nil) as Integer
Type Topic Plugin Version macOS Windows Linux iOS Targets
method Regular Expressions MBS RegEx Plugin 22.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Function: Matches a compiled regular expression against a given subject string, using a matching algorithm that is similar to Perl's.
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
Notes:
It returns offsets to what it has matched and to captured substrings via the matchData object. The return from Match() is one more than the highest numbered capturing pair that has been set (for example, 1 if there are no captures), zero if the vector of offsets is too small.
Raises exception in case of error.

A match context is needed only if you want to:
  • Set up a callout function
  • Set a matching offset limit
  • Change the heap memory limit
  • Change the backtracking match limit
  • Change the backtracking depth limit
  • Set custom memory management specifically for the match

StartOffsetCharacters is optional to start at a specific character in the text.

See also:

PCRE2CodeMBS.Match(Text as String, StartOffsetCharacters as Integer = 0, MatchContext as PCRE2MatchContextMBS = nil) as PCRE2MatchDataMBS
Type Topic Plugin Version macOS Windows Linux iOS Targets
method Regular Expressions MBS RegEx Plugin 22.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Function: Convenience variant of Match function.
Example:

// Compile a pattern
Dim Compiler As New PCRE2CompilerMBS
compiler.Pattern = "(\d+)([$€£]?)"
Dim code As PCRE2CodeMBS = Compiler.Compile

// now run a match
Dim Match1 As PCRE2MatchDataMBS = code.Match("abc") // -> nil as not found
Dim Match2 As PCRE2MatchDataMBS = code.Match("Täst 1234€ Case")

MessageBox match2.SubString(0)
Notes:
Performs match and returns the new PCRE2MatchDataMBS object.
Returns nil in case nothing is found.

See also:

PCRE2CodeMBS.MatchAll(Text as String, StartOffsetCharacters as Integer = 0, MatchContext as PCRE2MatchContextMBS = nil) as PCRE2MatchDataMBS()
Type Topic Plugin Version macOS Windows Linux iOS Targets
method Regular Expressions MBS RegEx Plugin 22.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Function: Matches pattern several times in the text.
Example:

// Compile a pattern
Dim Compiler As New PCRE2CompilerMBS
compiler.Pattern = "(\d)"
Dim code As PCRE2CodeMBS = Compiler.Compile

// now run a match
Dim Matches() As PCRE2MatchDataMBS = code.MatchAll("Täst 1234€ Case")

Dim SubString0 As String = matches(0).SubString(0)
Dim SubString1 As String = matches(1).SubString(0)
Dim SubString2 As String = matches(2).SubString(0)
Dim SubString3 As String = matches(3).SubString(0)

// see 4 results in debugger
Break
Notes:
This does a loop to go over text from start to end to match the pattern as often as it fits.
We try to avoid endless loops.

Returns an array with PCRE2MatchDataMBS objects, one for each match.

Some examples using this method:

PCRE2CodeMBS.Matches(Text as String, StartOffsetCharacters as Integer = 0, MatchContext as PCRE2MatchContextMBS = nil) as PCRE2IteratorMBS
Type Topic Plugin Version macOS Windows Linux iOS Targets
method Regular Expressions MBS RegEx Plugin 22.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Function: Runs match with an iterator.
Example:

Dim rx As New PCRE2CompilerMBS
rx.CaseLess = True
rx.DotAll = False
rx.Ungreedy = False
rx.NewLine = rx.kNewLineAnyCRLF
rx.Multiline = True
rx.Pattern = kMarkerPattern

Dim code As PCRE2CodeMBS = rx.Compile
Dim foundCount as integer

for each MatchData as PCRE2MatchDataMBS in code.Matches(TestString, 0)
foundCount = foundCount + 1
next
Notes:
Returns the iterator, so you can use it with for each loop.
May raie an error if something goes wrong.
PCRE2CodeMBS.Names as String()
Type Topic Plugin Version macOS Windows Linux iOS Targets
method Regular Expressions MBS RegEx Plugin 22.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Function: Queries name table.
Example:

Dim Compiler As New PCRE2CompilerMBS

// find numbers
compiler.Pattern = "(?<AA>\d+)"

Dim code As PCRE2CodeMBS = Compiler.Compile
Dim names() As String = code.Names

Break // see debugger
PCRE2CodeMBS.SerializeEncode as String
Type Topic Plugin Version macOS Windows Linux iOS Targets
method Regular Expressions MBS RegEx Plugin 22.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Function: Encodes a compiled pattern into a byte stream that can be saved on disc or elsewhere.
Example:

// Compile a pattern
Dim Compiler As New PCRE2CompilerMBS
compiler.Pattern = "(\d+)([$€£]?)"
Dim code1 As PCRE2CodeMBS = Compiler.Compile

// store somewhere compiled
Dim data As String = code1.SerializeEncode

// later rebuild it
Dim code2 As PCRE2CodeMBS = PCRE2CodeMBS.SerializeDecode(data)

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

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

MessageBox match.SubString(0)
Notes: Note that this is not an abstract format like Java or .NET. Conversion of the byte stream back into usable compiled patterns can only happen on a host that is running the same version of PCRE2, with the same code unit width, and the host must also have the same endianness, pointer width and size_t type.
PCRE2CodeMBS.Substitute(Text as String, Replacement as String, matchData as PCRE2MatchDataMBS = nil, StartOffsetCharacters as Integer = 0, MatchContext as PCRE2MatchContextMBS = nil) as String
Type Topic Plugin Version macOS Windows Linux iOS Targets
method Regular Expressions MBS RegEx Plugin 22.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Function: Matches a compiled regular expression against a given subject string, using a matching algorithm that is similar to Perl's.
Example:

// Compile a pattern
Dim Compiler As New PCRE2CompilerMBS
compiler.Pattern = "(\d)"
Dim code As PCRE2CodeMBS = Compiler.Compile

// replace all
code.SubstituteGlobal = True

// we replace all and duplicate all digits here:
Dim newText As String = code.Substitute("Täst 1234€ Case", "$1$1")

Break // see result in debugger
Notes:
It then makes a copy of the subject, substituting a replacement string for what was matched.

Text: The subject string
Replacement: the replacement string
matchData: The match data block, or is nil if you don't need the result.
StartOffsetCharacters: Offset in the subject at which to start matching.
MatchContext: A match context, or nil.

A match data block is needed only if you want to inspect the data from the final match that is returned in that block or if SubstituteMatched is set. A match context is needed only if you want to:

  • Set up a callout function
  • Set a matching offset limit
  • Change the backtracking match limit
  • Change the backtracking depth limit
  • Set custom memory management in the match context

Raises exception in case of error.

The options are controlled via properties:

Anchored Match only at the first position
EndAnchoredPattern can match only at end of subject
NotBOLSubject string is not the beginning of a line
NotEOLSubject string is not the end of a line
NotEmptyAn empty string is not a valid match
NotEmptyAtStartAn empty string at the start of the subject is not a valid match
NoJitDo not use JIT matching
NoUTFCheckDo not check the subject for UTF validity (only relevant if UTF was set at compile time)
PartialHardReturn PCRE2_ERROR_PARTIAL (-2) for a partial match even if there is a full match
PartialSoftReturn PCRE2_ERROR_PARTIAL (-2) for a partial match if no full matches are found.
PCRE2CodeMBS.SubstringNumberFromName(Name as String) as Integer
Type Topic Plugin Version macOS Windows Linux iOS Targets
method Regular Expressions MBS RegEx Plugin 22.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Function: Finds the number of a named substring capturing parenthesis in a compiled pattern, provided that it is a unique name.
Notes:
If the string is not found, you receive a negative value.
For other errors, we raise an exception.

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

Feedback: Report problem or ask question.

The biggest plugin in space...


Start Chat