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

RegEx.FindMatches

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

Component Version macOS Windows Linux Server iOS SDK
RegEx 5.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "RegEx.FindMatches"; RegExRef; Text; ExecuteOptions { ; ReturnWholeMatch; NoReturnEnding } )   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
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 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

Search for numbers in text:

Set Variable [$regex; Value:MBS("RegEx.Compile"; "(\d+)\D"; 512+1)]
Set Variable [$result; MBS("RegEx.FindMatches"; $regex; "aa 123 abc"; 0; 0)]
Set Variable [$r; Value:MBS("RegEx.Release"; $regex)]

Find cd and 34 in the following text:

Set Variable [$regex; Value:MBS("RegEx.Compile"; "<code>..(..)..</code>"; 512+1)]
Set Variable [$result; Value:MBS("RegEx.FindMatches"; $regex; "<code>abcdef</code>¶<code>123456</code>"; 0; 0)]
Set Variable [$r; Value:MBS("RegEx.Release"; $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"; pattern; CompileOptions );
result = MBS( "RegEx.FindMatches"; regex; text; ExecuteOptions ; 0 );
r = MBS("RegEx.Release"; regex)
]; result )

See also

Release notes

Example Databases

Blog Entries

This function checks for a license.

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


RegEx.Extract - RegEx.List