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

RegEx.Extract

Extracts found text.

Component Version macOS Windows Linux Server iOS SDK
RegEx 11.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "RegEx.Extract"; Text; Pattern; Rewrite { ; Options } )   More

Parameters

Parameter Description Example Flags
Text The text to use. "hello world"
Pattern The pattern to use. "l+"
Rewrite The output pattern.
Use \ followed by number to access captures.
"\1\1"
Options The PCRE options.
Can be given as text or number.
0 Optional

Result

Returns text or error.

Description

Extracts found text.
Similar like RegEx.Replace, but returns only the found text given to the pattern for output.

Examples

Extract phone number:

MBS( "RegEx.Extract"; "Call us at 01234/5678-90 to speak to sales."; "([0-9][0-9/\\-]+[0-9])"; "\1"; 1 )

Example result: 01234/5678-90

Find a german IBAN in a text:

Let([
Input = "Hello DE29100100100987654321 World!";
R = MBS( "IBAN.RegEx"; "DE");
R = substitute(R; "^"; "");
R = substitute(R; "$"; "");

Found = MBS("RegEx.Extract"; input; R; "\\0"; 0 )
]; Found)

Example result: DE29100100100987654321

Look for invoice number via regex:

MBS("RegEx.Extract";
"Rechnung Nr. 1234567 vom Mai 2020";
"(Nr|Number|No|Nummer|Nombre|Numbre)([. :]*)(\d+)";
"\3";
"caseless¶greedy")

Extract MBS Plugin version from container with Windows:

# extract plugin file
Set Variable [ $InfoText ; Value: MBS( "Container.GetText"; Install Plugin Update if needed::Plugin File Win 64bit; "FILE"; "Windows") ] 
# get version as text
Set Variable [ $version ; Value: MBS( "RegEx.Extract"; $infoText; "MBS FileMaker Plugin (\d+.\d+.\d+.\d+)"; "\1"; "greedy, caseless" ) ] 
Show Custom Dialog [ "MBS Version" ; $version ]

Extract MBS Plugin version from container with Linux:

# extract plugin file
Set Variable [ $InfoText ; Value: MBS( "Container.GetText"; Install Plugin Update if needed::Plugin File Linux; "FILE") ] 
# get version as text
Set Variable [ $version ; Value: MBS( "RegEx.Extract"; $infoText; "MBS FileMaker Plugin, version (\d+.\d+.\d+.\d+),"; "\1"; "greedy, caseless" ) ] 
Show Custom Dialog [ "MBS Version" ; $version ]

Extract MBS Plugin version from container with macOS:

# extract info file with metadata
Set Variable [ $InfoFile ; Value: MBS( "Archive.ExtractFile"; Install Plugin Update if needed::Plugin File Mac; "MBS.fmplugin/Contents/Info.plist" ) ] 
# get it as text
Set Variable [ $InfoText ; Value: MBS( "Container.GetText"; $InfoFile; "FILE") ]
# get version as text
Set Variable [ $version ; Value: MBS( "RegEx.Extract"; $infoText; "<key>CFBundleVersion</key>\s*<string>(.*)</string>"; "\1"; "greedy, caseless" ) ] 
Show Custom Dialog [ "MBS Version" ; $version ]

Extract everything following first word:

MBS("RegEx.Extract"; " Hello World!"; "\\s*(\\w*)\\s+(.*)"; "\\2"; "caseless,greedy")

Example result: "World!"

See also

Release notes

Example Databases

Blog Entries

This function checks for a license.

Created 19th February 2021, last changed 13th February 2024


RegEx.Execute - RegEx.FindMatches