Regular expressions (regex) allow you to find patterns in text strings. Regular expressions have a unique syntax that uses special characters to represent the patterns you want to find, and a variety of resources are available online if you want to familiarize yourself with how regular expressions work.
Note: For information on using regex with Cash Application Manager (CAM), see Use regex with capture groups to extract specific information from a bank file and Regular Expressions Support for BofA Wires, SVB, Wells Fargo, HSBC Wires and PNC Wires.
Contents
Regex for integrator.io
You can use regex to find, replace, prefix, or append instances of text patterns you define. The most common regex use cases for integrator.io wrap the regular expression in a handlebars format to allow the system to recognize that the pattern expressed should be parsed with a regex engine. When building a regular expression, you should first use a regex tester to verify your regular expression matches the patterns you want to capture. You can then use your regular expression with one of the following handlebars expressions to perform the operation within the context of a flow:
- regexMatch: Use this to match the input data based on the regular expression and return the data based on index and options variables.
- regexReplace: Use this to return a modified string where the pattern has been replaced.
- regexSearch: Use this to search for a match, and return the position of the result in the dataset, where 0=first position and 2=third position.
JavaScript string objects:
regexMatch, regexReplace, and regexSearch handlebars expressions require you to enter the following parameters:
- field: the field name containing the variable or values to be matched, replaced, or searched. You can reference a field or variable by typing its name without double quotes (or curly braces or parens).
- regex: the new value which will match, replace, or search the existing value.
- index: the position of the result in the dataset, where 0=first position and 2=third position.
- options: modifies the search flag of the expression. For example, regular expressions stop at the first match in the text content by default. The "g" flag indicates that the regular expression should be tested against all possible matches in a string. See Advanced searching with flags.
Note: The index parameter is not used in regexSearch.
Use regexReplace nested within a regexMatch expression to remove formatting from phone numbers
The following handlebars expression uses regexReplace to remove formatting to ten digit phone number fields.
{
"phone" : "(999) 888-7777"
}
This expression removes the parens from the first three digits, removes the following space character, and removes the hyphen after the next three digits yielding 9998887777
{{regexMatch (regexReplace phone "" "[^\d]" "g") "\d{10}$" "g"}}
Use regexMatch to extract a value between parentheses
The following handlebars expression uses regexMatch to extract the value contained between two parentheses. For example, if your field has a value that is formatted as follows:
{
"exampleField": "(BR12345)-WIT-1"
}
Use the following regexMatch expression to return only the value within the parentheses:
{{regexMatch exampleField "(?<=\()(.*?)(?=\))" "g"}}
This example returns the following:
{
BR12345
}
Comments
4 comments
Hi team, I'm trying to use an assertion as the example above, however I get the following error:
Input:
Handlebars:
Desired output:
When I run the following in the browser, the regex does give me the correct output:
I've tried a combination of different regex expressions, including and excluding the global flag and still nothing, it doesn't get past the '?'.
Also, it seems to be happening in NetSuite flows, both from the marketplace (Shopify -> NetSuite) and custom flows using NetSuite as an import.
Pablo Gonzalez is this only happening on NetSuite steps? This seems to be working in playground.
Pablo Gonzalez it looks like this error happens in preview, but it works in runtime. I'll pass this on internally, but you should be good to use it.
Please sign in to leave a comment.