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


Replace pattern once.

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


Parameter Description Example Flags
Text The text to use. "hello world"
Pattern The pattern to use. "l+"
Rewrite The output pattern. "\1\1"
Options The PCRE options.
Can be given as text or number.
0 Optional
All Whether to replace all occurances.
Pass 1 to replace all or 0 to replace once.
Default 0.
0 Optional
NthOffset Available in MBS FileMaker Plugin 13.5 or newer.
Number of occurrences to skip over on the start before doing replace.
e.g. pass 1 to skip first match and start replacing at second one.
0 Optional


Returns new text or error.


Replace pattern once.
You can replace the first match of pattern in text with rewrite pattern. Within rewrite pattern, backslash-escaped digits (\1 to \9) can be used to insert text matching corresponding parenthesized group from the pattern. \0 in rewrite refers to the entire matching text.

Caseless1Do caseless matching
CaseSensitive0Do case sensitive matching
Multiline2^ and $ match newlines within data
SingleLine0^ and $ do not match newlines within data
DotAll4. matches anything including NL
Extended8Ignore white space and # comments
Anchored16Force pattern anchoring
DollarEndOnly32$ not to match newline at end
NotBOL128Subject string is not the beginning of a line
NotEOL256Subject string is not the end of a line
Ungreedy512Invert greediness of quantifiers
Greedy0Be greedy.
NotEmpty1024An empty string is not a valid match
Empty0An empty string is a valid match
AutoCapture0Enable numbered capturing parentheses
NoAutoCapture4096Disable numbered capturing parentheses (named ones available)
AutoCallout16384Compile automatic callouts
NoAutoCallout0Don’t compile automatic callouts
Partial32768Allow partial results.
FirstLine262144Force matching to be before newline
DupNames524288Allow duplicate names for subpatterns
NewlineCR1048576Set CR as the newline sequence
NewlineLF2097152Set LF as the newline sequence
NewlineCRLF3145728Set CRLF as the newline sequence
NewlineAny4194304Recognize any Unicode newline sequence
NewlineAnyCRLF5242880Recognize CR, LF, and CRLF as newline sequences
BSRAnyCRLF8388608\R matches only CR, LF, or CRLF
BSRUnicode16777216\R matches all Unicode line endings
JavaScriptCompatible33554432JavaScript compatibility
NoStartOptimize67108864Disable match-time start optimizations
PartialHard134217728Return partial result if found before .
NotEmptyAtStart268435456An empty string at the start of the subject is not a valid match
UCP536870912Use Unicode properties for \d, \w, etc.



MBS( "RegEx.Replace"; "yabba dabba doo"; "b+"; "d" )

Example result: "yadba dabba doo"

Replace with multiline:

MBS( "RegEx.Replace"; "Hello¶World¶Testing"; "^World$"; "Welt"; "Multiline, NewlineAnyCRLF" )

Example result:

Try replaceing nth occurance:

MBS( "RegEx.Replace"; "John John John John"; "john"; "Thom"; "caseless"; 0; 0 ) & ¶ &
MBS( "RegEx.Replace"; "John John John John"; "john"; "Thom"; "caseless"; 0; 1 ) & ¶ &
MBS( "RegEx.Replace"; "John John John John"; "john"; "Thom"; "caseless"; 0; 2 ) & ¶ &
MBS( "RegEx.Replace"; "John John John John"; "john"; "Thom"; "caseless"; 0; 3 )

Example result:
Thom John John John
John Thom John John
John John Thom John
John John John Thom

See also

Release notes

Blog Entries

This function checks for a license.

Created 17th October 2017, last changed 31st October 2023

RegEx.ReleaseAll - RegEx.ReplaceAll