Regular expressions (known as RegEx or RegExp) are patterns used to match character combinations in strings. RegEx can be used in FileMaker for a variety of purposes.
RegEx use cases include:
- Validating field types (RegEx tests)
- For example:
j.doe@example.org
is a valid email format whilej@doe
is not.
- For example:
- Finding certain patterns (RegEx match and MatchAll)
- For example: Check if IP addresses exists in
I'm using the 1.1.1.1 and 8.8.8.8 public DNS servers
and return them, the RegEx function would output both1.1.1.1
and8.8.8.8
.
- For example: Check if IP addresses exists in
- Finding and replacing a text pattern (RegEx replace and ReplaceAll)
- For example: Redact all emails in
My email addresses are jdoe@example.com and j.doe@gmail.com
. The result would beMy email addresses are [REDACTED] and [REDACTED]
.
- For example: Redact all emails in
“A regular expression is a sequence of characters that define a search pattern. Usually such patterns are used by string-searching algorithms for “find” or “find and replace” operations on strings, or for input validation. It is a technique developed in theoretical computer science and formal language theory.”
Source: Wikipedia
Regular Expressions (RegEx) in FileMaker
Regular expressions can be implemented in FileMaker without advanced FileMaker or JavaScript development skills.
In this blog post, I’ll be only demonstrating RegEx tests for the sake of simplicity. Our next blog posts may cover topics such as Match, MatchAll, Replace, and ReplaceAll. I’ve included a demo file that illustrates the concepts in this article. In the demo file, you’ll find support for MatchAll, if that is useful for your solution.
Who uses RegEx?
Regular expressions are useful for both FileMaker power users and developers. The use of regular expressions will make your work as a developer more efficient. For FileMaker beginners, regular expressions can be an easy way to reliably validate fields or scrape certain values from data without advanced FileMaker skills.
The attached demo file works only with FileMaker 19. Please comment if you require a demo file for previous versions of FileMaker.
RegEx Patterns
An example of a RegEx pattern is: ^[a-zA-Z0-9]+$
. This pattern checks if the given string is made of alphanumeric characters only. You can use this tool to retrieve an explanation of a specific RegEx pattern. A list of resources, including tools about this topic, can be found at the end of this article.
^: the beginning of the string
[a-zA-Z0-9]+:
a-z: any character from 'a' to 'z'
A-Z: any character from 'A' to 'Z'
0-9: any number from '0' to '9'
+: (1 or more times (matching the most amount possible))
$: the end of the string
Finding or Creating new RegEx Patterns
- Create your own using a tool such as regex101.com
- Use existing regular expressions patterns on regexlib.com or regexhub.com
Integration overview
I prepared a script in JavaScript that can receive a string, a RegEx pattern and RegEx modifiers. RegEx tests can be executed using a script called RegExTest(RegEx,string,modifiers). The result of the script is either True or False, depending on the result of the RegEx test. The demo file includes a simpler integration example that can be found in the Sandbox layout.
Sandbox layout.
Example of a failed validation check through a RegEx Test.
Example of a successful validation check through a RegEx Test.
Try it out
- Open the demo file and make sure you’re on the “Simple Demo” layout
- Enter a valid email address in the “Email” field
- Click the “Check if valid email address” button
- You should see a dialog window showing a successful validation check
- Enter an invalid email address such as “jdoe@example”
- Click the “Check if valid email address” button
- You should see a dialog window showing a failed validation check
Open the “Sample form” layout to see an example of how to use this flow with the OnObjectValidate field trigger. If you don’t want to see the dialog messages, you can disable them in the “RegExValidateField(String¶Type)” script.
Conclusion
Regular expressions are very handy for extracting, validating and replacing strings and other data types. Using regular expressions should save developers a lot of time and improve the accuracy and capabilities of FileMaker scripts and functions, especially when it comes to ETL (Extract, transform, load) tasks. There’s a lot more that can be done with that wasn’t covered by this blog post and I hope that I get to cover more topics related to Regular Expressions (RegEx) in FileMaker. Let me know in the comments if you need help with the demo file, or need help implementing RegEx into your workflows.
RegEx explainers, resources and advanced testing tools
- Regex101 (excellent tool): https://regex101.com/r/hU2dI0/1
- W3schools.com (RegEx tutorial): https://www.w3schools.com/jsref/jsref_obj_RegExp.asp
- RegEx explainer: http://rick.measham.id.au/paste/explain.pl?regex=%5E%5Ba-zA-Z0-9%5D%2B%24
- Regex translator: https://www.regextranslator.com/
*This article was originally written for AppWorks, which has since joined Direct Impact Solutions. This article is intended for informative purposes only. To the best of our knowledge, this information is accurate as of the date of publication.