---
title: "How to use regular expressions"
canonical: "https://support.appfire.com/space/RUN/73074203/How%20to%20use%20regular%20expressions"
format: markdown
---
> Macro (aura-html)

# <span style="color: #000000">Overview</span>

<span style="color: #000000">The </span>*<span style="color: #000000">Run with a user form and parameters</span>*<span style="color: #000000"> macro makes use of</span> [regular expressions](http://en.wikipedia.org/wiki/Regular_expression) <span style="color: #000000">for pattern matching. Generally, just a simple </span><span style="color: #000000">understanding of regular expressions and a few examples are </span><span style="color: #000000">enough to get by for most use cases. This page has a few simple examples to get started. Use the references for more advanced information. It is recommended to test your regular expressions in one of the well-known regex testing sites such as</span> [RegexPlanet](http://www.regexplanet.com/advanced/java/index.html) <span style="color: #000000">or</span> [Regex101](https://regex101.com/)<span style="color: #000000">.</span>

> ✅ **Key tips**
> ✅ 
> ✅ - <span style="color: #000000">Dot or period (.) is a special regex character. If you really want to match on it, you need to escape it with a backslash: </span>**<span style="color: #000000">\</span>**<span style="color: #000000">.</span>
> ✅ - <span style="color: #000000">Don't be confused with generic pattern matching used for file systems for instance. On a file system, </span>*<span style="color: #000000">*.png</span>*<span style="color: #000000"> means all files ending with </span>*<span style="color: #000000">.png</span>*<span style="color: #000000">. That is an illegal regex expression. For regex you need: </span>*<span style="color: #000000">.*\.png</span>*<span style="color: #000000">, or to simplify: </span>**<span style="color: #000000">.</span>***<span style="color: #000000">*png</span>*<span style="color: #000000"> which finds all files ending in </span>*<span style="color: #000000">png</span>*<span style="color: #000000"> (not necessarily ending in an extension of PNG).</span>
> ✅ - <span style="color: #000000">Regex is </span>**<span style="color: #000000">case sensitive</span>**<span style="color: #000000"> by default. In most cases, use the case insensitive flag: </span>*<span style="color: #000000">(?i)</span>*<span style="color: #000000">. See one of the examples below.</span>
> ✅ - <span style="color: #000000">Use the </span>**<span style="color: #000000">Dotall</span>**<span style="color: #000000"> mode to match across line breaks. </span>
> ✅ 
> ✅ > Macro (legacy-content)

# <span style="color: #000000">Simple examples</span>

> Macro (table-plus)
> 
> | <span style="color: #000000">**Value**</span> | <span style="color: #000000">**Regex**</span> | <span style="color: #000000">**Matches**</span> | <span style="color: #000000">**Demonstrates**</span> |
> | --- | --- | --- | --- |
> | <span style="color: #000000">ABC</span> | <span style="color: #000000">A.C</span> | :check_mark: | <span style="color: #000000">. matches any single character</span> |
> | <span style="color: #000000">ABC</span> | <span style="color: #000000">A.*</span> | :check_mark: | <span style="color: #000000">* indicates 0 or more characters</span> |
> | <span style="color: #000000">ABC</span> | <span style="color: #000000">.*C</span> | :check_mark: |  |
> | <span style="color: #000000">A.B</span> | <span style="color: #000000">A\.B</span> | :check_mark: | <span style="color: #000000">Escape special regex characters with backslash if necessary</span> |
> | <span style="color: #000000">ABC</span> | <span style="color: #000000">AB*</span> | :cross_mark: | <span style="color: #000000">Regex is NOT generic matching</span> 🙂 |
> | <span style="color: #000000">ABC</span> | <span style="color: #000000">A.+</span> | :check_mark: | <span style="color: #000000">+ indicates 1 or more</span> |
> | <span style="color: #000000">ABC</span> | <span style="color: #000000">ABC.+</span> | :cross_mark: |  |
> | <span style="color: #000000">ABC</span> | <span style="color: #000000">ABC.*</span> | :check_mark: |  |
> | <span style="color: #000000">ABCD</span> | <span style="color: #000000">ABC.*</span> | :check_mark: |  |
> | <span style="color: #000000">ABC</span> | <span style="color: #000000">[ABCD]</span> | :check_mark: | <span style="color: #000000">[ ] indicates a class of characters</span> |
> | <span style="color: #000000">ABC</span> | <span style="color: #000000">[ABZ]</span> | :cross_mark: |  |
> | <span style="color: #000000">ABC8</span> | <span style="color: #000000">[A-Z0-9]</span> | :check_mark: | <span style="color: #000000">- indicates a range of characters</span> |
> | <span style="color: #000000">ABC</span> | <span style="color: #000000">[AB^C]</span> | :cross_mark: | <span style="color: #000000">^ in a class means NOT the following character</span> |
> | <span style="color: #000000">ABC</span> | <span style="color: #000000">DEF|ABC</span> | :check_mark: | <span style="color: #000000">| indicates OR</span> |
> | <span style="color: #000000">image.png</span> | <span style="color: #000000">.*png|.*jpg</span> | :check_mark: |  |
> | <span style="color: #000000">image.jpg</span> | <span style="color: #000000">.*png|.*jpg</span> | :check_mark: |  |
> | <span style="color: #000000">image.JPG</span> | <span style="color: #000000">.*png|.*jpg</span> | :cross_mark: | <span style="color: #000000">defaults to case sensitive matching</span> |
> | <span style="color: #000000">image.JPG</span> | <span style="color: #000000">(?i).*png|.*jpg</span> | :check_mark: | <span style="color: #000000">(?i) indicates case insensitive matching</span> |
> | <span style="color: #000000">ABAB</span> | <span style="color: #000000">(AB)+</span> | :check_mark: | <span style="color: #000000">() indicates a grouping</span> |
> | <span style="color: #000000">ABCD</span> | <span style="color: #000000">(AB)+</span> | :cross_mark: |  |
> | <span style="color: #000000">112233</span> | <span style="color: #000000">\d+</span> | :check_mark: | <span style="color: #000000">\d for digits</span> |
> | <span style="color: #000000">A B</span> | <span style="color: #000000">A\s*B</span> | :check_mark: | <span style="color: #000000">\s for whitespace</span> |
> | <span style="color: #000000">ABC</span> | <span style="color: #000000">\S*</span> | :check_mark: | <span style="color: #000000">\S for non whitespace</span> |
> |  | <span style="color: #000000">\S+</span> | :cross_mark: | <span style="color: #000000">Value must have at least 1 non whitespace character</span> |
> | <span style="color: #000000">A</span> | <span style="color: #000000">\S+</span> | :check_mark: |  |
> | <span style="color: #000000">XYZ,ABC,UVW</span> | <span style="color: #000000">.*\bABC\b.*</span> | :check_mark: | <span style="color: #000000">Word boundaries. Finding words in a comma or blank separated list</span> [using word boundaries](http://www.regular-expressions.info/wordboundaries.html) |
> | <span style="color: #000000">XYZ,ABCD,UVW</span> | <span style="color: #000000">.*\bABC\b.*</span> | :cross_mark: |  |
> | <span style="color: #000000">ABC</span> | <span style="color: #000000">(?m)(^ABC$)|(^ABC,)|(,ABC,)|(,ABC$)</span> | :check_mark: | <span style="color: #000000">Looking for text matches in a comma separated list by covering all cases: only, start, middle, and end. This uses the multi-line flag: (?m)</span> |
> | <span style="color: #000000">XYZ,ABC,UVW</span> | <span style="color: #000000">(?m)(^ABC$)|(^ABC,)|(,ABC,)|(,ABC$)</span> | :check_mark: |  |
> | <span style="color: #000000">XYZ,ABC DEF,UVW</span> | <span style="color: #000000">(?m)(^ABC$)|(^ABC,)|(,ABC,)|(,ABC$)</span> | :cross_mark: |  |

# <span style="color: #000000">Advanced examples</span>

| <span style="color: #000000">**Value**</span> | <span style="color: #000000">**Regex**</span> | <span style="color: #000000">**Matches**</span> | <span style="color: #000000">**Find**</span> | <span style="color: #000000">**Demonstrates**</span> |
| --- | --- | --- | --- | --- |
| <span style="color: #000000">example.txt</span> | `^((?!\.png).)*$` | :cross_mark: | :check_mark: | <span style="color: #000000">Find string </span>**<span style="color: #000000">not</span>**<span style="color: #000000"> containing a word. In this example, files that do not have a </span>*<span style="color: #000000">.png</span>*<span style="color: #000000"> extension</span> |
| <span style="color: #000000">example.png</span> | `^((?!\.png).)*$` | :cross_mark: | :cross_mark: | <span style="color: #000000">Find string </span>**<span style="color: #000000">not</span>**<span style="color: #000000"> containing a word. In this example, files that do not have a </span>*<span style="color: #000000">.png</span>*<span style="color: #000000"> extension</span> |
| <span style="color: #000000">example.jpeg</span> | `(?=^((?!\.png).)*$)(?=^((?!\.jpeg).)*$)` | :cross_mark: | :cross_mark: | <span style="color: #000000">Find string </span>**<span style="color: #000000">not</span>**<span style="color: #000000"> containing a word. In this example, files that do not have a </span>*<span style="color: #000000">.png</span>*<span style="color: #000000"> or </span>*<span style="color: #000000">.jpeg</span>*<span style="color: #000000"> extension</span> |
| <span style="color: #000000">collateral wholesale retail</span> | `.*(?=.*\bretail\b.*)(?=.*\bcollateral\b.*).*` | :check_mark: |  | <span style="color: #000000">Match exact words anywhere in string. In this case, a blank separated list of labels and both collateral and retail must be included for the match to be successful</span> |
| <span style="color: #000000">wholesale retail</span> | `.*(?=.*\bretail\b.*)(?=.*\bcollateral\b.*).*` | :cross_mark: |  | <span style="color: #000000">Both are required for a match</span> |
| <span style="color: #000000">merger acquisition</span> | `.*\b(?:merger|acquisition)\b.*` | :check_mark: |  | <span style="color: #000000">Match string containing either word</span> |

# References

- [RegexOne](http://regexone.com/) <span style="color: #000000">- interactive tutorials to learn how to construct regular expressions</span>
- [Regexlib.com](http://regexlib.com/) <span style="color: #000000">- searchable collection of user-contributed regular expressions</span>
- [RegexPlanet test site](http://www.regexplanet.com/advanced/java/index.html) <span style="color: #000000">- test your expressions quickly</span>
- [Regex101 test site](https://regex101.com/) <span style="color: #000000">- understand a regex expression and test it</span>
- [Wikipedia regular expressions](http://en.wikipedia.org/wiki/Regular_expression)
- [Regular expression reference](http://www.regular-expressions.info/reference.html)
- [Quick reference ](http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#sum)<span style="color: #000000">- best once you have the concepts</span>
- [Using word boundaries](http://www.regular-expressions.info/wordboundaries.html)
- [Regular expression to match string not containing a word?](http://stackoverflow.com/questions/406230/regular-expression-to-match-string-not-containing-a-word)