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 |
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 option | Number | Description |
Anchored | 16 | Force pattern anchoring |
Not BOL | 128 | Subject string is not the beginning of a line |
Not EOL | 256 | Subject string is not the end of a line |
Not Empty | 1024 | An empty string is not a valid match |
Partial | 32768 | Allow partial results. |
Newline CR | 1048576 | Set CR as the newline sequence |
Newline LF | 2097152 | Set LF as the newline sequence |
Newline CRLF | 3145728 | Set CRLF as the newline sequence |
Newline Any | 4194304 | Recognize any Unicode newline sequence |
Newline Any CRLF | 5242880 | Recognize CR, LF, and CRLF as newline sequences |
BSR Any CRLF | 8388608 | \R matches only CR, LF, or CRLF |
BSR Unicode | 16777216 | \R matches all Unicode line endings |
No start optimize | 67108864 | Disable match-time start optimizations |
Partial Hard | 134217728 | Return partial result if found before . |
Not Empty At Start | 268435456 | An empty string at the start of the subject is not a valid match |
UCP | 536870912 | Use 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
- IsError
- RegEx.CaptureCount
- RegEx.Compile
- RegEx.NamedSubstring
- RegEx.Release
- RegEx.Results
- RegEx.Study
- RegEx.Substring
Example Databases
Blog Entries
This function checks for a license.
Created 26th October 2014, last changed 26th April 2023