Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

RegEx.Execute

Executes a statement.

Component Version macOS Windows Linux Server iOS SDK
RegEx 4.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "RegEx.Execute"; RegExRef; Text; ExecuteOptions { ; Offset } )   More

Parameters

Parameter Description Example Flags
RegExRef The reference number for the regular expression returned from RegEx.Compile. $regex
Text The text to search. "Hello"
ExecuteOptions The options for executing.
Can be given as text or number.
0
Offset Optional the offset in the text to start. Can be in range from 0 to length(text). 0 Optional

Result

Returns result or error.

Description

Executes a statement.
You need to compile pattern before with RegEx.Compile function.
Returns the number of results.
Use RegEx.Results function to get list of results.

Execute optionNumberDescription
Anchored16Force pattern anchoring
Not BOL128Subject string is not the beginning of a line
Not EOL256Subject string is not the end of a line
Not Empty1024An empty string is not a valid match
Partial32768Allow partial results.
Newline CR1048576Set CR as the newline sequence
Newline LF2097152Set LF as the newline sequence
Newline CRLF3145728Set CRLF as the newline sequence
Newline Any4194304Recognize any Unicode newline sequence
Newline Any CRLF5242880Recognize CR, LF, and CRLF as newline sequences
BSR Any CRLF8388608\R matches only CR, LF, or CRLF
BSR Unicode16777216\R matches all Unicode line endings
No start optimize67108864Disable match-time start optimizations
Partial Hard134217728Return partial result if found before .
Not Empty At Start268435456An empty string at the start of the subject is not a valid match
UCP536870912Use Unicode properties for \d, \w, etc.

Please pass sum of the numbers to select options.

Examples

Run query and show substrings:

Set Variable [ $Pattern ; Value: "H(.*)o (.)or(..)" ]
Set Variable [ $Text ; Value: "Hello World Test" ]
# Compile
Set Variable [ $Regex ; Value: MBS("RegEx.Compile"; $Pattern; "CaseLess") ]
If [ MBS("isError") ]
    Show Custom Dialog [ $Regex ]
    Exit Script [ Text Result: ]
End If
Set Variable [ $ExecuteResult ; Value: MBS("RegEx.Execute"; $RegEx; $Text; "") ]
If [ MBS("IsError") = 0 ]
    Show Custom Dialog [ "Captures" ; MBS("RegEx.CaptureCount"; $RegEx) ]
    Show Custom Dialog [ "Substrings" ; MBS("RegEx.Substring"; $RegEx) & ¶ &
MBS("RegEx.Substring"; $RegEx; 1) & ¶ &
MBS("RegEx.Substring"; $RegEx; 2) & ¶ &
MBS("RegEx.Substring"; $RegEx; 3)]
End If
# free last
Set Variable [ $r ; Value: MBS("RegEx.Release"; $RegEx) ]

Loop and find all matches for pattern:

Set Variable [ $pattern ; Value: "(USt\-?ID:?|USt\-?IdNR\.?:?|Umsatzsteuer\-?ID:?|VAT\-?ID:?)[\s]?(DE)[\s]?([0-9]{9})" ]
Set Variable [ $ExecuteOptions ; Value: 0 ]
Set Variable [ $CompileOptions ; Value: "caseless" ]
Set Variable [ $regex ; Value: MBS("RegEx.Compile"; $Pattern; $CompileOptions) ]
Set Variable [ $offset ; Value: 0 ]

Loop
    Set Variable [ $r ; Value: MBS("RegEx.Execute"; $regex; RegEx::Text; $ExecuteOptions; $offset) ]
    Exit Loop If [ $r < 4 ]
    Set Variable [ $s1 ; Value: MBS("RegEx.Substring"; $RegEx; 1) ]
    Set Variable [ $s2 ; Value: MBS("RegEx.Substring"; $RegEx; 2) ]
    Set Variable [ $s3 ; Value: MBS("RegEx.Substring"; $RegEx; 3) ]
    Show Custom Dialog [ $s1 & ¶ & $s2 & ¶ & $s3 ]
    Exit Loop If [ MBS("IsError") ]
    Set Variable [ $offset ; $offset + Value: GetAsNumber(GetValue(MBS("RegEx.Results"; $regex); 2)) ]
End Loop
Set Variable [ $r ; Value: MBS("RegEx.Release"; $RegEx) ]

See also

Example Databases

Blog Entries

This function checks for a license.

Created 26th October 2014, last changed 26th April 2023


RegEx.DataDetector - RegEx.Extract