RegEx.Execute
-------------

Executes a statement.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [RegEx](component_RegEx.md) | [4.4](newinversion44.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "RegEx.Execute"; RegExRef; Text; ExecuteOptions { ; Offset } ) 

**MBS**( **"RegEx.Execute"** /\* Executes a statement. \*/  
**$RegExRef**; /\* The reference number for the regular expression returned from [RegEx.Compile](RegExCompile.md). e.g. $regex \*/   
**$Text**; /\* The text to search. e.g. "Hello" \*/   
**$ExecuteOptions**; /\* The options for executing.  
Can be given as text or number. e.g. 0 \*/   
**$Offset**) /\* Optional; Optional the offset in the text to start. Can be in range from 0 to length(text). e.g. 0 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| RegExRef | The reference number for the regular expression returned from [RegEx.Compile](RegExCompile.md). | $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](RegExCompile.md) function.  
Returns the number of results.  
Use [RegEx.Results](RegExResults.md) 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](RegExCompile.md)"; $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](RegExCaptureCount.md)"; $RegEx ) \]   
 Show Custom Dialog \[ "Substrings" ; MBS ("[RegEx.Substring](RegExSubstring.md)"; $RegEx ) &amp; ¶ &amp;  
MBS ("[RegEx.Substring](RegExSubstring.md)"; $RegEx ; 1) &amp; ¶ &amp;  
MBS ("[RegEx.Substring](RegExSubstring.md)"; $RegEx ; 2) &amp; ¶ &amp;  
MBS ("[RegEx.Substring](RegExSubstring.md)"; $RegEx ; 3)\]   
End If  
\# free last   
Set Variable \[ $r ; Value: MBS ("[RegEx.Release](RegExRelease.md)"; $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](RegExCompile.md)"; $Pattern ; $CompileOptions ) \]   
Set Variable \[ $offset ; Value: 0 \]   
  
Loop  
 Set Variable \[ $r ; Value: MBS ("RegEx.Execute"; $regex ; RegEx::Text ; $ExecuteOptions ; $offset ) \]   
 Exit Loop If \[ $r &lt; 4 \]   
 Set Variable \[ $s1 ; Value: MBS ("[RegEx.Substring](RegExSubstring.md)"; $RegEx ; 1) \]   
 Set Variable \[ $s2 ; Value: MBS ("[RegEx.Substring](RegExSubstring.md)"; $RegEx ; 2) \]   
 Set Variable \[ $s3 ; Value: MBS ("[RegEx.Substring](RegExSubstring.md)"; $RegEx ; 3) \]   
 Show Custom Dialog \[ $s1 &amp; ¶ &amp; $s2 &amp; ¶ &amp; $s3 \]   
 Exit Loop If \[ MBS ("IsError") \]   
 Set Variable \[ $offset ; $offset + Value: GetAsNumber(GetValue(MBS ("[RegEx.Results](RegExResults.md)"; $regex ); 2)) \]   
End Loop  
Set Variable \[ $r ; Value: MBS ("[RegEx.Release](RegExRelease.md)"; $RegEx ) \]  
### See also

- [IsError](IsError.md)
- [RegEx.CaptureCount](RegExCaptureCount.md)
- [RegEx.Compile](RegExCompile.md)
- [RegEx.NamedSubstring](RegExNamedSubstring.md)
- [RegEx.Release](RegExRelease.md)
- [RegEx.Results](RegExResults.md)
- [RegEx.Study](RegExStudy.md)
- [RegEx.Substring](RegExSubstring.md)

### Example Databases

- [RegEx/RegEx](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/RegEx/RegEx.shtml#2ScriptAnchor_)

### Blog Entries

- [Regular Expressions in FileMaker](https://www.mbsplugins.de/archive/2023-03-19/Regular_Expressions_in_FileMak/monkeybreadsoftware_blog_filemaker)
- [MBS Filemaker Plugin, version 4.5pr4](https://www.mbsplugins.de/archive/2014-12-19/MBS_Filemaker_Plugin_version_4/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 26th October 2014 , last changed 25th February 2026

  
[RegEx.DataDetector](RegExDataDetector.md) - [RegEx.Extract](RegExExtract.md)

[HTML Version](RegExExecute.shtml)