Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

RegExMBS class

Type Topic Plugin Version macOS Windows Linux Console & Web iOS
class Regular Expressions MBS Tools Plugin 6.2 Yes Yes Yes Yes No
Function: A class for fast Regular Expression Search in a perl compatible way.
Example:
dim r as new RegExMBS
dim searchString as string = ".o"

if r.Compile(searchString) then

dim s as string="Hello World"

dim start as Integer = 0
while r.Execute(s,start)>0

dim p as Integer = r.OffsetCharacters(0)
dim l as Integer = r.OffsetCharacters(1)-r.OffsetCharacters(0)

MsgBox "Found "+searchString+" on position "+str(p)+" with length "+str(l)+" in """+s+""""

start = r.Offset(1)
wend

else
MsgBox "failed to compile"
end if
Notes:
uses the PCRE library. You may check the PCRE documentation.

The RegExMBS class has different defaults as the built in RegEx class in Real Studio.

You may want to set options like this:

RB: CaseSensitive = false
MBS: CompileOptionCaseLess = true

RB: DotMatchAll = false
MBS: CompileOptionDotAll = false

RB: Greedy = true
MBS: CompileOptionUngreedy = false

RB: LineEndType = 0
MBS: CompileOptionNewLineAnyCRLF = true and ExecuteOptionNewLineAnyCRLF = true

RB: MatchEmpty = true
MBS: ExecuteOptionNotEmpty = false

and you want to set CompileOptionMultiline to true for multi line match.

Feedback, Comments & Corrections

Error Constants

Constant Value Description
ErrorBadCount -15 This error is given if the value of the ovecsize argument is negative.
ErrorBadMagic -4 PCRE 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.
ErrorBadNewLine -23 An invalid combination of Newline options was given.
ErrorBadOffset -24 The value of startoffset was negative or greater than the length of the subject, that is, the value in length.
ErrorBadOption -3 An unrecognized bit was set in the options argument.
ErrorBadPartial -13 This code is no longer in use. It was formerly returned when the PCRE_PARTIAL option was used with a compiled pattern containing items that were not supported for partial matching. From release 8.00 onwards, there are no restrictions on partial matching.
ErrorBadUTF8 -10 A string that contains an invalid UTF-8 byte sequence was passed as a subject. However, if PCRE_PARTIAL_HARD is set and the problem is a truncated UTF-8 character at the end of the subject, ErrorShortUTF8 is used instead.
ErrorBadUTF8Offset -11 The 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 or the end of the subject.
ErrorCallOut -9
ErrorDFARecurse -20
ErrorDFAUCond -17
ErrorDFAUItem -16
ErrorDFAUMLimit -18
ErrorDFAWSSize -19
ErrorInternal -14 An unexpected internal error has occurred. This error could be caused by a bug in PCRE or by overwriting of the compiled pattern.
ErrorMatchLimit -8 The backtracking limit, as specified by the match_limit field in a pcre_extra structure (or defaulted) was reached.
ErrorNoMatch -1 The subject string did not match the pattern.
ErrorNoSubstring -7 This error is used by the substring functions.
ErrorNull -2 Either code or subject was passed as "", or ovector was "" and ovecsize was not zero.
ErrorNullWSLimit -22
ErrorPartial -12 The subject string did not match, but it did match partially.
ErrorPlugin -99 Generic error for something wrong with the plugin state.
Like no current regex object internally or wrong function parameters.
ErrorRecursionLimit -21 The internal recursion limit, as specified by the match_limit_recursion field in a pcre_extra structure (or defaulted) was reached. See the description above.
ErrorShortUTF8 -25 The subject string ended with an incomplete (truncated) UTF-8 character, and the PCRE_PARTIAL_HARD option was set. Without this option, ErrorBadUTF8 is returned in this situation.
ErrorUnknownNode -6
ErrorUnknownOpcode -5 While 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.

This class has no sub classes.

Some examples which use this class:


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


RectControl   -   RegistrationEngineMBS




Links
MBS Xojo Chart Plugins