1. Overview
Regular expressions can be used in:
- Find() and Replace()
- Lookup and matching formulas: Match(), vLookUp(), hLookUp()
To enable regular expressions, specify the SEARCH::RegEx flag (value 8192) as described in the Formula Composer window.
In Find(), you may also use SEARCH::RegExStr. If used, the function returns the matching substring instead of the index.
Examples:
=find("\w\d{2,3}", "abc4567ghr", 1, SEARCH::RegEx) → 3
=find("\w\d{2,3}", "abc4567ghr", 1, SEARCH::RegExStr) → "c456"
2. Returning Capturing Groups
You can specify which capturing group should be returned:
- 32 — first group
- 64 — second group
- 128 — third group
Useful for extracting file components:
Extension:
=find("(\.[^.]+)$", "c:\file.txt", 1, 32+SEARCH::RegExStr)
Folder:
=find("^(.*[\\\/])?(\.*.*?)(\.[^.]+?|)$", "c:\folder1\file.txt", 1, 32+SEARCH::RegExStr)
File name without extension:
=find("^(.*[\\\/])?(\.*.*?)(\.[^.]+?|)$", "c:\file.txt", 1, 64+SEARCH::RegExStr)
3. Regular Expression Examples
| abc | Cells containing “abc” |
| .bc | Any character + “bc” |
| \Aabc | Starts with “abc” |
| abc\z | Ends with “abc” |
| \Aabc.*123\z | Starts with “abc”, ends with “123” |
| abc\d\z | Ends with “abc” + digit |
| ^a\d+ | Line starting with “a” + digits |
| ^a\d* | Line starting with “a” + optional digits |
| a\d*$ | Line ending with “a” + optional digits |
| [ab]+c | “abc”, “aabc”, “abbabc”… but not “c” alone |
| [ab]*c | Same as above, including “c” |
| [^ab]+c | Ends with “c”, contains no “a” or “b” |
| \w\d{2,3} | Letter + 2–3 digits |
| ^ab\d{2,3}c | Starts with “ab”, 2–3 digits, “c” |
| abc|xyz | Contains “abc” or “xyz” |
See PCRE regular expression syntax summary.
4. Replace() with Regular Expressions
If SEARCH::RegEx is set, the replace string may contain:
- Capturing group references: \1, \2, …
- \l, \L, \u, \U — case conversion
- \r, \n — line feed / newline
- \s — space
5. Examples
Example 1
| Find: | ab+ |
| Content: | abcdefaabb |
| Replace: | x |
| Result: | xcdefax |
Example 2
| Find: | (.)a+\d{1,3} |
| Content: | abc aa0102 |
| Replace: | \1 |
| Result: | abc 2 |
Example 3
| Find: | (ab) |
| Content: | abcdef ghijk abb123 |
| Replace: | \u\1\l\1xyz\s |
| Result: | ABabxyz cdef ghijk ABabxyz b123 |
Example 4
| Find: | \R |
| Content: | abc def ghi |
| Replace: | \s |
| Result: | abc def ghi |