RegEx.FindMatches
-----------------

Finds in a text all matches of a given pattern and returns list.

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

MBS( "RegEx.FindMatches"; RegExRef; Text; ExecuteOptions { ; ReturnWholeMatch; NoReturnEnding } ) 

**MBS**( **"RegEx.FindMatches";** /\* Finds in a text all matches of a given pattern and returns list. \*/  
**$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 \*/   
**$ReturnWholeMatch**; /\* Optional; Pass 1 to return whole match including text you have in the pattern. Else pass 0 to get only the text from your captures.e.g. 1 \*/   
**$NoReturnEnding**) /\* Optional; Pass 1 to have no extra newline character on the end of the returned list. Default is 0 to include one to easily concat lists.e.g. 1 \*/ 

### 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 |  |
| ReturnWholeMatch | Pass 1 to return whole match including text you have in the pattern. Else pass 0 to get only the text from your captures. | 1 | Optional |
| NoReturnEnding | Pass 1 to have no extra newline character on the end of the returned list. Default is 0 to include one to easily concat lists. | 1 | Optional |

### Result

Returns list or error.

### Description

Finds in a text all matches of a given pattern and returns list.  
Can be used for example to find tokens or placeholders in a text.  
If your search pattern has no captures, please pass 1 for ReturnWholeMatch or you won't see anything in result.  
  
| 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

Search for numbers in text:

 Set Variable \[$regex ; Value:MBS ("[RegEx.Compile](RegExCompile.md)"; "(\\d+)\\D"; 512+1)\]  
Set Variable \[$result ; MBS ("RegEx.FindMatches"; $regex ; "aa 123 abc"; 0; 0)\]  
Set Variable \[$r ; Value:MBS ("[RegEx.Release](RegExRelease.md)"; $regex )\]  
Find cd and 34 in the following text:

 Set Variable \[$regex ; Value:MBS ("[RegEx.Compile](RegExCompile.md)"; "&lt;code&gt;..(..)..&lt;/code&gt;"; 512+1)\]  
Set Variable \[$result ; Value:MBS ("RegEx.FindMatches"; $regex ; "&lt;code&gt;abcdef&lt;/code&gt;¶&lt;code&gt;123456&lt;/code&gt;"; 0; 0)\]  
Set Variable \[$r ; Value:MBS ("[RegEx.Release](RegExRelease.md)"; $regex )\]  
Find matches in multiline text:

 Let (\[  
pattern = "^GR.";  
text = "GR1¶GR2 ¶GR3 ";  
CompileOptions = 2 /\* multiline \*/ + 1 /\* caseless \*/ + 4194304 /\* newline any \*/;  
ExecuteOptions = 4194304 /\* newline any \*/;  
regex = MBS ("[RegEx.Compile](RegExCompile.md)"; pattern; CompileOptions );  
result = MBS ( "RegEx.FindMatches"; regex; text; ExecuteOptions ; 0 );  
r = MBS ("[RegEx.Release](RegExRelease.md)"; regex)  
\]; result )  
### See also

- [RegEx.Compile](RegExCompile.md)
- [RegEx.Release](RegExRelease.md)

### Release notes

- **Version 9.5**
    - Added NoReturnEnding parameter to [RegEx.FindMatches](http://www.mbsplugins.eu/RegExFindMatches.shtml) function.
- **Version 8.2**
    - Improved speed for [RegEx.FindMatches](http://www.mbsplugins.eu/RegExFindMatches.shtml) function a little bit.

### Example Databases

- [RegEx/RegEx Find all matches in text](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/RegEx/RegEx%20Find%20all%20matches%20in%20text.shtml#1ScriptAnchor_)

### Blog Entries

- [MBS Plugin Advent calendar: 19 - RegEx](https://www.mbsplugins.de/archive/2023-12-19/MBS_Plugin_Advent_calendar_19_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 9.5pr5](https://www.mbsplugins.de/archive/2019-10-29/MBS_FileMaker_Plugin_version_9/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 8.2pr2](https://www.mbsplugins.de/archive/2018-04-11/MBS_FileMaker_Plugin_version_8/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 7.5pr8](https://www.mbsplugins.de/archive/2017-11-18/MBS_FileMaker_Plugin_version_7/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 5.1pr4](https://www.mbsplugins.de/archive/2015-04-08/MBS_FileMaker_Plugin_version_5/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 5.1pr1](https://www.mbsplugins.de/archive/2015-03-16/MBS_FileMaker_Plugin_version_5/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 15th March 2015 , last changed 26th April 2023

  
[RegEx.Extract](RegExExtract.md) - [RegEx.List](RegExList.md)

[HTML Version](RegExFindMatches.shtml)