There is one other application of regular expressions in our system which has not been covered in this thread and I wanted to highlight. As with the previous commentary, regular expressions are used to match answers to a predefined pattern, which then allows us take further actions.
When building workflows in the TrueContext solution, you can utilize regular expressions to set up a condition in a Conditional Logic element. By setting up a Conditional Logic "If" statement to compare an answer to a pattern, for example:
- Case-sensitive text
- Ends with
- Starts with
- Wildcard characters (single and multiple)
You can then configure a "Then" statement to present the user on the mobile application with a logical next step based on these parameters. As an example; you could configure the conditional logic element with a condition where if Question A on Page 1 is answered anything matching [0-9a-f]{32}, which is essentially a 32-character hexadecimal string, then we want to display Question F on Page 2 because we need to record a photo for evidence.
------------------------------
David Casal Del Castillo
Manager, Customer Success
TrueContext
Ottawa
------------------------------
Original Message:
Sent: 08-26-2021 11:22
From: Ian Chamberlain
Subject: Regex, Regex and more Regex
Regex is a short form for Regular Expressions (more info: Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patterns) They are used to "match" on a number of different patterns that might be input into a form. In ProntoForms there are 2 places where Regex can and should be used when possible. We will cover both of those applications and a few tips and tricks for building out those Regular Expressions in this article.
- Answer Validation - see Custom Validation (Data Type: Free Text) Using Regex as a custom validation method allows you to be 100% certain that the information that is being input into the form is exactly what you are expecting. If you want to make sure that the number they input starts with a 2, regex can do that. Make sure that there are 5 characters (no more - no less), regex can do that. We can not put examples of all the different ways to use Regex to perform this validation but there is tons of information online about it.
- Data Destination Filtering - see Custom Filter Rules (Applying Filtering to Data Destinations) We can also use Regex when applying a filter to a data destination to determine if the destination will get triggered or not. All the same rules apply here as they do in the Custom Validation.
Some things to note. When dealing with Regex, you will almost always want the start of the expression to be a ^ (which indicates the beginning of a string) and end your expression with a $ (meaning the end of the string). From there, you can use a tool like RegExr: Learn, Build, & Test RegEx to figure out if the expression that was built is going to match the strings that you put in the form. When you are first trying to come up with your expression - I would always suggest a quick google search because with the complexity of Regex expressions, no doubt someone has the expression figured out that you need.
------------------------------
Ian Chamberlain
Implementation Specialist
ProntoForms
------------------------------