How to use regular expressions in formulas | Zoho Sheet

Regular expressions in formulas

Regular expressions are patterns that can be used to include single or multiple characters in search. While Wildcards can be used for simple searches, regular expressions can be applied for advanced use cases.
 
The patterns used in regular expressions can consist of a combination of characters, operators, and constructs. Let's look at each category of patterns and their use in regular expressions.
 
Characters 
Below are the frequently used characters for search via regex. The backslash indicates that the following character has a special meaning during search.
Character
Description
Sample Pattern
Sample Matches
\d
Matches any digit character from 0 to 9.
\d
2 in a2z
0 in a-a=0
\D
Matches any character that is not a digit.
\D
a and z in a2z
a and a in a-a=0
\n
 
 
 
\s
Matches any whitespace character like space, tab, new line.
.\s.
o and S in Zoho Sheet
n and 5 in
Version
5
\S
Matches any non-whitespace character.
\S
Zoho and Sheet in Zoho Sheet
Version and 5 in
Version
5
\t
Matches a tab.
.\t
o in Zoho\tSheet
\w
Matches any alphanumeric character including ASCII letters, digits, and underscore.
\w
Hello in Hello!
email in @email
\W
Matches any character excluding alphanumeric characters and underscore.
\W
! in Hello!
@ in @email
.
Matches any single character except line break.
.en
hen, pen, ten, @en
\
Escapes the special meaning of a character during search. Eg., "\." can be used to search for "."
\w+\.
Mr. and Mrs.
 
 
Character Classes 
Character classes can be used to match anyone of the given set of characters, including letters, digits, and symbols. By default, the matches are case-sensitive.
 
 
Character Class
Description
Sample Pattern
Sample Matches
[characters]
Matches any single character given in the brackets.
h[iu]t
hit, hut
[^characters]
Matches any single character not given in the brackets.
h[^iu]t
h@t, hat, hot
[from-to]
Matches any single character in the range given in brackets.
[a-z]
[A-Z]
[0-9]
Any letter in lowercase
Any letter in uppercase
Any digit from 0 to 9
 
Quantifiers 
Quantifiers specify the number of occurrences of a character/character class/a group for a match. Applies to the preceding character.
 
Quantifier
Description
Sample Pattern
Sample Matches
*
Matches previous element zero or more times.
she*
sh, she, shee in sheet
+
Matches previous element one or more times.
she+
she, shee in sheet
?
Matches previous element zero or one time.
br?at
brat, bat
*?
Matches the previous element zero or more times, but as few times as possible.
she*?
sh in sheet
+?
Matches the previous element one or more times, but as few times as possible.
she+?
she in sheet
??
Matches the previous element zero or one time, but as few times as possible.
br??at
bat
{n}
Matches the previous element "n" times.
ab{4}
Order10{3}
abbbb
Order1000
{n,}
Matches the previous element "n" or more times.
ab{2,}
Order10{1,}
abb, abbb,...
Order10, Order100, Order1000,...
{n,m}
Matches the previous element between "n" and "m" times.
ab{2,4}
Order10{0,1}
abb, abbb, abbbb
Order1, Order10
{n,}?
Matches the previous element "n" or more times, but as few times as possible.
\d{3,}?
123, 1234
{n,m}?
Matches the previous element between "n" and "m" times, but as few times as possible.
\d{2,5}?
12, 123
 
Anchors 
Anchors can be used to specify a position in the given string for a match.
 
 
Anchor
Description
Sample Pattern
Sample Matches
^
The match must occur at the start of the given string. In multiline strings, it must occur at the start of the line.
^\d{1}
2 in 2 Orders
$
The match must occur at the end of the given string, or before \n at end of string. In multiline strings, it must occur at the end of the line or before \n at the end of line.
\d{4}$
1234 in Emp ID 1234
\A
The match must occur at the start of the given string.
\A\d{1}
2 in 2 Orders
\b
The match occur within a boundary between a /w and a /W character.
\bsheet\b
sheet in zoho sheet but not in spreadsheet
\B
The match must not occur within a \b boundary.
\bsheet\b
sheet in spreadsheet but not in zoho sheet
\G
The match must occur at the position where the previous match ended. In case of no previous match, then at the position in string where the matching started.
 
 
\z
The match must occur at the end of the string.
\d{4}\z
1234 in Emp ID 1234
\Z
The match must occur at end of the string or before \n at the end of string.
\d{4}\Z
1234 in Emp ID 1234
 
Zoho Sheet supports both Wildcards and regular expressions for match. Click here to learn more about the wildcard characters and their examples.