Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

Next items

RegExMBS.Compile(pattern as string) as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 6.2 Yes Yes Yes Yes No
Function: Compiles a pattern.
Example:
dim r as new RegExMBS
dim searchString as string = ".o"

if r.Compile(searchString) then
msgbox "OK"
else
MsgBox "failed to compile"
end if
Notes:
Some predefined patterns like \b do not support Unicode well, so you may work around that by using your own pattern.

Returns true on success and false on failure.
ErrorMessage, Lasterror, ErrorOffset and Handle are set.

The following table lists the error codes than may be returned by Compile(), along with the error messages that may be returned by both compiling functions.

0no error
1\ at end of pattern
2\c at end of pattern
3unrecognized character follows \
4numbers out of order in {} quantifier
5number too big in {} quantifier
6missing terminating ] for character class
7invalid escape sequence in character class
8range out of order in character class
9nothing to repeat
10operand of unlimited repeat could match the empty string
11internal error: unexpected repeat
12unrecognized character after (?
13POSIX named classes are supported only within a class
14missing )
15reference to non-existent subpattern
16erroffset passed as NULL
17unknown option bit(s) set
18missing ) after comment
19parentheses nested too deeply
20regular expression too large
21failed to get memory
22unmatched parentheses
23internal error: code overflow
24unrecognized character after (?<
25lookbehind assertion is not fixed length
26malformed number after (?(
27conditional group contains more than two branches
28assertion expected after (?(
29(?R or (?digits must be followed by )
30unknown POSIX class name
31POSIX collating elements are not supported
32this version of PCRE is not compiled with PCRE_UTF8 support
33spare error
34character value in \x{...} sequence is too large
35invalid condition (?(0)
36\C not allowed in lookbehind assertion
37PCRE does not support \L, \l, \N, \U, or \u
38number after (?C is > 255
39closing ) for (?C expected
40recursive call could loop indefinitely
41unrecognized character after (?P
42syntax error after (?P
43two named groups have the same name
44invalid UTF-8 string
45support for \P, \p, and \X has not been compiled
46malformed \P or \p sequence
47unknown property name after \P or \p

Feedback, Comments & Corrections

RegExMBS.CompileMemory(pattern as memoryblock, ByteOffset as Integer) as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 6.3 Yes Yes Yes Yes No
Function: Compiles a pattern.
Notes:
Same as Compile, but the text is stored in a memoryblock and must be a 0 terminated C string.
Be careful to use valid UTF8 input and provide offset in byte units and not in characters.

Feedback, Comments & Corrections

RegExMBS.ConfigBSR as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 11.2 Yes Yes Yes Yes No
Function: Returns an integer whose value indicates what character sequences the \R escape sequence matches by default.
Notes: A value of 0 means that \R matches any Unicode line ending sequence; a value of 1 means that \R matches only CR, LF, or CRLF. The default can be overridden when a pattern is compiled or matched.

Feedback, Comments & Corrections

RegExMBS.ConfigLinkSize as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 11.2 Yes Yes Yes Yes No
Function: Returns an integer that contains the number of bytes used for internal linkage in compiled regular expressions.
Notes: The value is 2, 3, or 4. Larger values allow larger regular expressions to be compiled, at the expense of slower matching. The default value of 2 is sufficient for all but the most massive patterns, since it allows the compiled pattern to be up to 64K in size.

Feedback, Comments & Corrections

RegExMBS.ConfigMallocThreshold as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 11.2 Yes Yes Yes Yes No
Function: The output is an integer that contains the threshold above which the POSIX interface uses malloc() for output vectors.

Feedback, Comments & Corrections

RegExMBS.ConfigMatchLimit as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 11.2 Yes Yes Yes Yes No
Function: Returns an integer that gives the default limit for the number of internal matching function calls in a Execute execution.

Feedback, Comments & Corrections

RegExMBS.ConfigMatchLimitRecursion as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 11.2 Yes Yes Yes Yes No
Function: Returns an integer that gives the default limit for the depth of recursion when calling the internal matching function in a Execute() execution.

Feedback, Comments & Corrections

RegExMBS.ConfigNewLine as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 11.2 Yes Yes Yes Yes No
Function: What newline character is used as default.
Notes: The output is an integer whose value specifies the default character sequence that is recognized as meaning "newline". The four values that are supported are: 10 for LF, 13 for CR, 3338 for CRLF, -2 for ANYCRLF, and -1 for ANY. Though they are derived from ASCII, the same values are returned in EBCDIC environments. The default should normally correspond to the standard sequence for your operating system.

Feedback, Comments & Corrections

RegExMBS.ConfigStackRecurse as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 11.2 Yes Yes Yes Yes No
Function: Returns an integer that is set to one if internal recursion when running Execute() is implemented by recursive function calls that use the stack to remember their state.
Notes: This is the usual way that PCRE is compiled. The output is zero if PCRE was compiled to use blocks of data on the heap instead of recursive function calls. In this case, malloc and free are called to manage memory blocks on the heap, thus avoiding the use of the stack.

Feedback, Comments & Corrections

RegExMBS.ConfigUnicodeProperties as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 11.2 Yes Yes Yes Yes No
Function: Returns true if unicode properties are available.
Notes: Should be true for the plugin.

Feedback, Comments & Corrections

RegExMBS.ConfigUTF8 as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 11.2 Yes Yes Yes Yes No
Function: Whether UTF8 is supported.
Notes: If this ever is false, please complain. This plugin is designed to work only on UTF8 strings for best performance.

Feedback, Comments & Corrections

RegExMBS.Constructor(VecSize as Integer = 0)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 13.4 Yes Yes Yes Yes No
Function: The constructor.
Notes:
You pass here the internal vector size which limits how many substrings you can find.
For 20 substrings, you need to pass (20+1)*3 for vector size.

Feedback, Comments & Corrections

RegExMBS.Escape(text as string) as string
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 7.8 Yes Yes Yes Yes No
Function: Escapes the string.
Example:
dim r as new RegExMBS

dim s as string = "Hello []"
dim e as string = r.Escape(s)
MsgBox e // shows Hello \[\]

dim d as string = r.Unescape(e)
MsgBox d // shows original string
Notes:
The string is converted to UTF8 and all the RegEx special characters are escaped.
Returns "" on low memory.

Feedback, Comments & Corrections

RegExMBS.Execute(start as Integer = 0) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 13.1 Yes Yes Yes Yes No
Function: Performs a search with the compiled pattern again.
Notes: You can use this variant of execute to continue a search in the same string/memoryblock at a new starting offset.

See also:

Feedback, Comments & Corrections

RegExMBS.Execute(text as string, start as Integer = 0) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 6.2 Yes Yes Yes Yes No
Function: Performs a search with the compiled pattern.
Example:
dim r as RegExMbs
dim s as string
dim c as Integer

s="123 ABC 456"

r=new RegExMBS
if r.Compile(" \D+ ") then
c=r.Execute(s,0)
MsgBox str(c)+" "+str(r.Offset(0))+" "+str(r.Offset(1))
// shows: 1 3 8
// 1 for number of results
// 3 for 3 bytes before the matched pattern
// 8 for the 8 bytes before the end of the matched pattern
end if
Notes:
Returns the number of found offsets.
text must be in UTF-8 text encoding.
Start must be 0 for the first character and the byte offset for other chacters. Do not pass values from OffsetCharacters here!

Return values from Execute:
If Execute() fails, it returns a negative number. The following are defined in the header file:

PCRE_ERROR_NOMATCH -1The subject string did not match the pattern.
PCRE_ERROR_NULL -2Either code or subject was passed as "".
PCRE_ERROR_BADOPTION -3An unrecognized bit was set in the options argument.
PCRE_ERROR_BADMAGIC -4PCRE stores a 4-byte "magic number" at the start of the compiled code, to catch the case when it is passed a junk pointer and to detect when a pattern that was compiled in an environment of one endianness is run in an environment with the other endianness. This is the error that PCRE gives when the magic number is not present.
PCRE_ERROR_UNKNOWN_NODE -5While running the pattern match, an unknown item was encountered in the compiled pattern. This error could be caused by a bug in PCRE or by overwriting of the compiled pattern.
PCRE_ERROR_NOMEMORY -6If a pattern contains back references, but the ovector that is passed to Execute() is not big enough to remember the referenced substrings, PCRE gets a block of memory at the start of matching to use for this purpose. If the call via pcre_malloc() fails, this error is given. The memory is automatically freed at the end of matching.
PCRE_ERROR_MATCHLIMIT -8The backtracking limit, as specified by the match_limit field in a pcre_extra structure (or defaulted) was reached.
PCRE_ERROR_RECURSIONLIMIT -21The internal recursion limit, as specified by the match_limit_recursion field in a pcre_extra structure (or defaulted) was reached.
PCRE_ERROR_CALLOUT -9This error is never generated by Execute() itself. It is provided for use by callout functions that want to yield a distinctive error code. See the pcrecallout documentation for details.
PCRE_ERROR_BADUTF8 -10A string that contains an invalid UTF-8 byte sequence was passed as a subject.
PCRE_ERROR_BADUTF8_OFFSET -11The UTF-8 byte sequence that was passed as a subject was valid, but the value of startoffset did not point to the beginning of a UTF-8 character.
PCRE_ERROR_PARTIAL -12The subject string did not match, but it did match partially. See the pcrepartial documentation for details of partial matching.
PCRE_ERROR_BADPARTIAL -13The PCRE_PARTIAL option was used with a compiled pattern containing items that are not supported for partial matching. See the pcrepartial documentation for details of partial matching.
PCRE_ERROR_INTERNAL -14An unexpected internal error has occurred. This error could be caused by a bug in PCRE or by overwriting of the compiled pattern.
PCRE_ERROR_BADCOUNT -15This error is given if the value of the ovecsize argument is negative.

See also:

Feedback, Comments & Corrections

RegExMBS.ExecuteMemory(text as memoryblock, ByteOffset as Integer = 0, ByteLength as Integer = 0) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 6.3 Yes Yes Yes Yes No
Function: Performs a search with the compiled pattern.
Notes:
Same as Execute, but the text is stored in a memoryblock.
Be careful to use valid UTF8 input and provide offset and length in byte units and not in characters.
If ByteLength is zero, we take the length of the memoryblock.

Feedback, Comments & Corrections

RegExMBS.ExecuteMemoryMT(text as memoryblock, ByteOffset as Integer = 0, ByteLength as Integer = 0) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 13.1 Yes Yes Yes Yes No
Function: Performs a search with the compiled pattern.
Notes:
Same as ExecuteMemory, but more thread friendly.
The work is performed on an extra thread, so this function can yield time to other Xojo (Real Studio) threads. For best user experience run this command on a Xojo (Real Studio) thread, so your GUI stays responsive. But all the thread overhead is only useful if the execution takes long.

Feedback, Comments & Corrections

RegExMBS.ExecuteMT(start as Integer = 0) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 13.1 Yes Yes Yes Yes No
Function: Performs a search with the compiled pattern.
Notes:
Same as Execute, but more thread friendly.
The work is performed on an extra thread, so this function can yield time to other Xojo (Real Studio) threads. For best user experience run this command on a Xojo (Real Studio) thread, so your GUI stays responsive. But all the thread overhead is only useful if the execution takes long.

See also:

Feedback, Comments & Corrections

RegExMBS.ExecuteMT(text as string, start as Integer = 0) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 13.1 Yes Yes Yes Yes No
Function: Performs a search with the compiled pattern.
Notes:
Same as Execute, but more thread friendly.
The work is performed on an extra thread, so this function can yield time to other Xojo (Real Studio) threads. For best user experience run this command on a Xojo (Real Studio) thread, so your GUI stays responsive. But all the thread overhead is only useful if the execution takes long.

See also:

Feedback, Comments & Corrections

RegExMBS.InfoNameEntry(Index as Integer) as string
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 13.4 Yes Yes Yes Yes No
Function: Queries a name entry in the list of captures.
Notes: Only valid after pattern was compiled.

Feedback, Comments & Corrections

RegExMBS.Match(text as string) as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 16.0 Yes Yes Yes Yes No
Function: Checks if current search pattern matches against given text.
Example:
dim r as new RegExMBS

if r.Compile("e.l") then

if r.Match("Hello") then
MsgBox "match"
end if

if r.Match("Helro") then
MsgBox "wrong match"
end if
end if

See also:

Feedback, Comments & Corrections

RegExMBS.Match(text() as string, inverse as boolean = false) as string()
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 16.0 Yes Yes Yes Yes No
Function: Checks if current search pattern matches against given text array.
Example:
dim r as new RegExMBS

r.CompileOptionCaseLess = true

if r.Compile("e.l") then

dim t() as string = array("Hello", "World", "Xojo", "REALbasic")

dim match1() as string = r.Match(t)
dim match2() as string = r.Match(t, true)

MsgBox "Matching: "+Join(match1, ", ")+EndOfLine+"Other: "+Join(match2, ", ")
end if
Notes:
Returns the list of matching values.
If inverse is set to true, it returns the list of non matching values.

See also:

Feedback, Comments & Corrections

RegExMBS.Match(text() as Variant, inverse as boolean = false) as string()
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 16.0 Yes Yes Yes Yes No
Function: Checks if current search pattern matches against given variant array.
Example:
dim r as new RegExMBS

r.CompileOptionCaseLess = true

if r.Compile("e.l") then

dim dic as new Dictionary
dic.Value("Hello") = 1
dic.Value("World") = 2
dic.Value("Xojo") = 3
dic.Value("REALbasic") = 4

dim match1() as string = r.Match(dic.keys)
dim match2() as string = r.Match(dic.keys, true)

MsgBox "Matching: "+Join(match1, ", ")+EndOfLine+"Other: "+Join(match2, ", ")
end if
Notes:
The variant array should have entries which convert well to string.
Returns the list of matching values.
If inverse is set to true, it returns the list of non matching values.

See also:

Feedback, Comments & Corrections

RegExMBS.Offset(index as Integer) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 6.2 Yes Yes Yes Yes No
Function: Get the offset in the offset list with given index in bytes.
Example:
dim r as RegExMbs
dim s as string
dim c as Integer

s="123 äöü ABC 456"

r=new RegExMBS
if r.Compile(".ö.") then
c=r.Execute(s,0)
MsgBox str(c)+" "+str(r.Offset(0))+" "+str(r.Offset(1))
// shows: 1 4 10
// 1 for ubound of the offset array
// 4 for 4 bytes before the matched pattern
// 10 for the 10 bytes before the end of the matched pattern
end if

r=new RegExMBS
if r.Compile(".\xF6.") then // finds ö using Unicode codepoint
c=r.Execute(s,0)
MsgBox str(c)+" "+str(r.Offset(0))+" "+str(r.Offset(1))
// shows: 1 4 10
// 1 for ubound of the offset array
// 4 for 4 bytes before the matched pattern
// 10 for the 10 bytes before the end of the matched pattern
end if
Notes:
If you found a pattern in a string you get here:

indexoffset
0start of matched pattern
1end of matched pattern
2start of subexpression 1
3end of subexpression 1
2*nstart of subexpression n
2*n+1end of subexpression n

Invalid indexes return 0.
Count is the number of entries here.

Feedback, Comments & Corrections

RegExMBS.OffsetCharacters(index as Integer) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 6.3 Yes Yes Yes Yes No
Function: Get the offset in the offset list with given index in characters.
Example:
dim r as new RegExMBS
dim searchString as string = ".o"

if r.Compile(searchString) then

dim s as string="äöü Hello World"

if r.Execute(s,0)>0 then
dim lines(-1) as string

lines.Append str(R.Count)+" offset found."
lines.Append "In Bytes:"
lines.Append " Start of matched patern: "+str(R.Offset(0))
lines.Append " End of matched patern: "+str(R.Offset(1))
lines.Append " Length of matched patern: "+str(R.Offset(1)-r.Offset(0))

lines.Append "In Characters:"
lines.Append " Start of matched patern: "+str(R.OffsetCharacters(0))
lines.Append " End of matched patern: "+str(R.OffsetCharacters(1))
lines.Append " Length of matched patern: "+str(R.OffsetCharacters(1)-r.OffsetCharacters(0))

MsgBox Join(lines,EndOfLine)
end if

else
MsgBox "failed to compile"
end if
Notes:
This function is identical to Offset(), but returns characters instead of bytes.
Works only with valid UTF-8 strings as input.
Value is calculated on each function call based on Offset(index) and current text.

If you found a pattern in a string you get here:

indexoffset
0start of matched pattern
1end of matched pattern
2start of subexpression 1
3end of subexpression 1
2*nstart of subexpression n
2*n+1end of subexpression n

Invalid indexes return 0.
Count is the number of entries here.

Please note that if you just need offsets for calling Mid() function, you can get better performance by using just Offset and MidB function. Than neither Mid and OffsetCharacters need to calculate the character offset.

Feedback, Comments & Corrections

RegExMBS.Replace(NewText as string) as string
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 6.2 Yes Yes Yes Yes No
Function: Replaces the text on the current found position and returns the complete new text.
Notes:
You need to call Execute before.
Lasterror is set.
NewText must have UTF-8 text encoding.

\0 references the whole found pattern, \1 to \15 the subexpressions.
\t is replaced with chr(9), \r and \n with chr(13) and \\ with \.

Feedback, Comments & Corrections

RegExMBS.ReplaceAll(Target as string, NewText as string = "") as string
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 6.2 Yes Yes Yes Yes No
Function: Searches the target string for current pattern and replaces all occurrences with the new text.
Notes:
You need to call Compile before to initialize the pattern and you should call Study before to optimize the pattern.
Lasterror is set.
Target and NewText must have UTF-8 text encoding.

\0 references the whole found pattern, \1 to \15 the subexpressions.
\t is replaced with chr(9), \r and \n with chr(13) and \\ with \.

Feedback, Comments & Corrections

RegExMBS.ReplaceSelection(NewText as string) as string
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 6.2 Yes Yes Yes Yes No
Function: Replaces the text on the current found position and returns new text for that selection.
Notes:
This method is for text editors where you will store result in editfield.seltext to replace the current selection.
Lasterror is set.
You need to call Execute before.
NewText must have UTF-8 text encoding.

\0 references the whole found pattern, \1 to \15 the subexpressions.
\t is replaced with chr(9), \r and \n with chr(13) and \\ with \.

Feedback, Comments & Corrections

RegExMBS.StringNumber(name as string) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Regular Expressions MBS Tools Plugin 6.2 Yes Yes Yes Yes No
Function: This convenience function finds the number of a named substring capturing parenthesis in a compiled pattern.
Notes:
name: Name whose number is required
The yield of the function is the number of the parenthesis if the name is found, or PCRE_ERROR_NOSUBSTRING otherwise.

Feedback, Comments & Corrections

Next items

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




Links
MBS Xojo Plugins