#056 BC REGULAR EXPRESSIONS
To meet SaaS environments and Universal Code initiative requirements, it is not possible to directly use .NET libraries. Therefore, to replace the RegEx libraries, the RegEx Codeunit offers the possibility of pattern matching using regular expressions.
The following methods are available on the RegEx codeunit:
- IsMatch(Input: Text; Pattern: Text; StartAt: Integer): Boolean – Indicates whether the regular expression finds a match in the input string, beginning at the specified starting position in the string.
- Match(Input: Text; Pattern: Text; StartAt: Integer; var Matches: Record Matches) – Searches the input string for the occurrences that match a regular expression, beginning at the specified starting position in the string.
- Split(Input: Text; Pattern: Text; “Count”: Integer; var “Array”: List of [Text]) – Splits an input string a specified maximum number of times into an array of substrings, at the positions defined by a regular expression pattern.
- Replace(Input: Text; Pattern: Text; Replacement: Text; “Count”: Integer): Text – Replaces strings that match a regular expression pattern with a specified replacement string.
Example
Scenario: Imagine that, for a given text, we pretend to identify all references to License Plates with the format 2Letters-2Number-2Letters.
The action would return:
Variations:
- Be case Insensitive: [A-Z,a-z]{2}\-[0-9]{2}\-[A-Z,a-z]{2}
- Find any License Plate: [A-Z]{2}\-[0-9]{2}\-[A-Z]{2}|[0-9]{2}\-[A-Z]{2}\-[A-Z]{2}|[A-Z]{2}\-[A-Z]{2}\-[0-9]{2}
To ease developers’ life, RegEx101 is a website with a built-in manual where the regular expressions can be created and tested.
If these expressions are frequently used, it might be a good idea to have an auxiliar table linked with pattern by the OnLookUp trigger: