Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Guides   Examples
New in version: 7.2   7.3   7.4   7.5   8.0   8.1   8.2   8.3   8.4   8.5    Statistic  

RegEx.Compile

Compiles a pattern.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
RegEx 4.4 Yes Yes Yes Yes Yes
MBS( "RegEx.Compile"; Pattern; CompilerOptions )   More

Parameters

Parameter Description Example value
Pattern The pattern to use. "H(.*)"
CompilerOptions A number for the options to use. e.g. 1 for case insensitive or 512 for ungreedy. Add 2 for multiline.
Can be given as text or number.
"multiline¶ungreedy"

Result

Returns reference number or error.

Description

Compiles a pattern.
Returns the regular expression reference which you can than pass to other functions.
Remember to use RegEx.Free to free memory later.
You compile a pattern once. If you use RegEx.Execute several times on it, it may be worth using RegEx.Study for better performance.
Please use \r instead of \n for the pattern as FileMaker uses Mac line endings.
RegEx reference numbers are starting at 13000 and counting up for each new expression.

Compile optionNumberDescription
Caseless1Do caseless matching
Multiline2^ and $ match newlines within data
Dot All4. matches anything including NL
Extended8Ignore white space and # comments
Anchored16Force pattern anchoring
Dollar End Only32$ not to match newline at end
Ungreedy512Invert greediness of quantifiers
No Auto Capture4096Disable numbered capturing parentheses (named ones available)
Auto Callout16384Compile automatic callouts
FirstLine262144Force matching to be before newline
Dup Names524288Allow duplicate names for subpatterns
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
JavaScript Compatible33554432JavaScript compatibility
No start optimize67108864Disable match-time start optimizations

Please pass sum of the numbers to select options.

Examples

Compile with double escapement:

Set Variable [ $regex ; Value: MBS("RegEx.Compile"; "\\\""; 512+1) ]

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.Free"; regex)
]; result )

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"; $Pattern; $CompileOptions) ]
Set Variable [ $offset ; Value: 0 ]

Loop
    Set Variable [ $r ; Value: MBS("RegEx.Execute"; $regex; RegEx::Text; $ExecuteOptions; $offset) ]
    Exit Loop If [ $r < 4 ]
    Set Variable [ $s1 ; Value: MBS("RegEx.Substring"; $RegEx; 1) ]
    Set Variable [ $s2 ; Value: MBS("RegEx.Substring"; $RegEx; 2) ]
    Set Variable [ $s3 ; Value: MBS("RegEx.Substring"; $RegEx; 3) ]
    Show Custom Dialog [ $s1 & ¶ & $s2 & ¶ & $s3 ]
    Exit Loop If [ MBS("IsError") ]
    Set Variable [ $offset ; $offset + Value: GetAsNumber(GetValue(MBS("RegEx.Results"; $regex); 2)) ]
End Loop
Set Variable [ $r ; Value: MBS("RegEx.Free"; $RegEx) ]

See also

Example Databases

Created 26th October 2014, last changed 29th June 2018


RegEx.CaptureCount   -   RegEx.Execute

Feedback: Report problem or ask question.




Links
MBS Xojo Plugins