What is Regex?
Regex means “regular expression” and it is is a sequence of characters that specifies 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. Xtracta applies it for fields in order to allow that the information there can be altered automatically.
Simple Regex Samples
| Problem | Regex Solution (Matching Pattern) |
|---|---|
| Match the first word in a string | /^[^ ]+/ |
| Match the first word and first space | /^[^_]* / |
| Match everything up to including the “:” | /^[^_]*\:/ |
| Match commas | /\,/ |
| Match all Special characters | /[|\?\*\+\.\{\}\[\]\(\)\:\%\-\^\$\,\\\/]*/ |
| Match all letters | /[a-zA-Z]/ |
| Match all non-numerals | /\D/ |
| Match all numbers | /[0-9]/ or /\d/ |
| Limit field to 20 characters | (?<=^.{20}).* |
| Match everything (Useful to copy to another field) | /[\s\S]+/ |
| Match just the first six numbers | /[0-9]{6}/ |
| Match just the last three characters | /.{3}$/ |
| Remove everything from space and Del onward | / Del.*/ |
| Keep only numbers and “.” | /[^0-9.]/ |
| Not blank | /^.{1,}$/ |
| Blank | /^$/ |
| Trim to ten characters | (?<=^.{10}).* |
| Limit dates to certain years | `(?:^$) |
| Check if a field has badword or stinky | `^((?!^(badword.* |
| Match several words | `(?:^ |
Case Scenario - Removing Characters
If a field was meant to only have numbers, without spaces or letters, it is possible to create a Strip and Replace rule that can remove everything except numbers:

As a result for this Strip and Replace rule, the Replacement String is empty, therefore all characters that are no digits will be find and replaced for nothing, in other words, removed:

This can also be done the opposite way or for one or more characters as required.
Case Scenario - Replacing Characters
In some cases, it’s necessary to replace a few characters/digits or words for something else, it is also possible to create a Strip and Replace rule that perform the replacement:

Once the word “INV-” is added to the field, it will automatically be replaced by “Invoice -“:

This can also be done with one or characters/words.
Relevant Information
Regex has some special characters, those characters must be escaped with \ before them otherwise they won't be recognized in the solution.
Special characters: | ? * + . , : { } [ ] ( ) % – \ / ^ $
A common tool when creating regex is the website Regex 101 that allows you to practice and create rule watching in real time what is that rule actually doing.