Skip to content
Gallery
RegexMatch, RegexReplace
Share
Explore

icon picker
RegexMatch, RegexReplace

Formula: RegexMatch() and RegexReplace()
Category: String
broken-robot.svg
RegexMatch()
Checks if text values match a “regular expression”
It’s kind of like saying...
Hey Coda, I have a bunch of text for you. Now look at this pattern...can you Identify this pattern in my text?

robot-2.svg
RegexReplace()
Replaces text via “regular expression”
Or put another way...
Hey Coda, I have a bunch of text. Now look at this pattern...can you Identify this pattern in my text and replace it with this?
RegexMatch() and RegexReplace() share two parameters:
text-color (2).svg
Text

RegexMatch(Text, Regular Expression)

This is the text you want to seach with your pattern.
opacity.svg
RegularExpression

RegexMatch(Text, RegularExpression)

This is the pattern you're looking to search for within your text.
RegexReplace() takes one additional parameter:
find-and-replace.svg
ReplacementText

RegexReplace(Text, RegularExpression, Replacement Text)

This is the pattern you want to replace your text with.



The first time I read the documentation on Regex I said: “What the f**k is this?” and quickly left the page. Go ahead, look at it and tell me you’re not confused → []
Despite it being scary to those unacquainted, Regex is by far one of the most useful formulas you can have in your tool-belt and there are a few powerful expressions you can learn that will help you with your Coda data.

What is Regex?

Regular Expression or (Regex) is one of the most powerful, flexible, and efficient text processing approaches. Regex has its own terminologies, conditions, and syntax; it is, in a sense, a mini programming language. Regex can be used to add, remove, isolate, and manipulate all kinds of text and data [].
In short, Regex is a way of reliably locating patterns in text. You use short hand “code” to match patterns of text within a longer string. For example:
\s
Matches a space
the.{3}
Matches the word “the” followed by any three characters
[0-9]{4}\s
Matches any 4 number characters in a row followed by a space
For educational purposes, we are going to refer to Regex as a small little robot. A small little robot that takes commands (in the form of regexExpressions) and then looks for those patterns in text.

How to use Regex in Your Docs

One could, and some have, on Regex. So rather than teach you Regex from the ground-up, the Coda School is going to help you master a couple patterns that will make Regex a useful and powerful formula for your workflows. We will start with some patterns you need to know followed by a couple of example use-cases with those patterns.

Need to Know Patterns (Aka - Regex Expressions)

Click into the view button below to learn more about the pattern or follow along below to see how they are used in combination to do some magical things
View
Pattern Number
Pattern
Description
1
Pattern 1
.*
Matching all following characters
2
Pattern 2
\s
Matching a space
3
Pattern 3
[a-zA-Z]
Matching letter characters
4
Pattern 4
[0-9]
Matching number characters
5
Pattern 5
{4}
Matching a certain number of characters
6
Pattern 6
+
Matches more than zero items of a specific character
7
Pattern 7
\
The escape character allowing you to match an actual character that normally has a special meaning in Regex
8
Pattern 8
|
The or operator
There are no rows in this table

Regex with Addresses

Below is a list of addresses that a business owner, Freddy, has on file for customers. In order to better analyze the addresses and answer questions like “In what state do a majority of my customers live?” - Freddy uses Regex formulas in the “Address Line Only” and “State” columns.
Full Address
Address Line Only
State
1
1313 Disneyland Dr, Anaheim, CA 92802
1313 Disneyland Dr
CA
2
444 Castro St. Suite 1200, Mountain View, CA 94041
444 Castro St. Suite 1200
CA
3
148 Main St., Greenwich NY 12834
148 Main St.
NY
4
999 Enchanted Way, Simi Valley, CA 93065
999 Enchanted Way
CA
There are no rows in this table
Expand the sections below to see how Regex is used and an explanation of the patterns used to draw out this information.

Address Line Only

What pattern(s) did this solution use? Select any that apply.
1
Answer
This solution used pattern 1.

State

What pattern(s) did this solution use? Select any that apply.
1
1
Answer
This solution used pattern 1, 3, and 5.
Other things to note
This solution used a hidden formula called RegexExtract().
When you extract text from a string, the Regex Robot extracts everything you tell him to. In this case, you asked him to extract a space, two capital letters, and another space. Therefore the end result would have had extra spaces in it. Hence the Trim(), which then allowed us to return just the state value itself.



Regex with Larger Text

The
following table
is a list of survey responses a business owner has collected. The owner wants to answer two questions with her data and uses Regex to answer them in the gray columns below.
Did each responder provide a valid email address?
Which responders left information about either our prices or our service?
Name
Email
Survey Response
Valid Email Address
Price/Service
1
Danielle Perez
dperez@comcast.net
Your service was decent. I did have one negative experience with a customer service representative though where they didn’t know how to answer my questions
2
Catherine Myers
cmyers@outlookcom
The service was better than I expected! I chatted with one individual online who provided excellent answers to my problems and immediately provided me a refund
3
Bryan Curry
bcurry@comcast.net
I am exteremely unhappy with the interactions I had with your staff in store. Right when I walked in your staff looked up at me, didn’t acknowledge that I was there, and then went back to texting on their phones
4
Jacob Mercado
jmercado@outlook.com
There is no place I love more than your store. The aesthetics in store are EXCELLENT, the service is always swift, and your prices are always low
5
Lauren Hampton
lhampton@gmailcom
If there was a different store in town I would probably try it out, but as you are the only one - Ill keep coming for now.
There are no rows in this table
Expand the sections below to see how Regex is used and an explanation of the patterns used to draw out this information.

Valid Email Address

What pattern(s) did this solution use? Select any that apply.
Answer
This solution used pattern 1, 6 and 7.
Other things to note
Email validation is another beast. While the above Regex Expression will allow you to validate most emails, email validation is notoriously difficult to do.
From Google, here’s another email validation regex string you can use: ^[\w-+.]+@[\w-]+\.[\w-.]+$
Simply googling “regex expression to match _______” can give you tons of ideas and examples!

Price Service

What pattern(s) did this solution use? Select any that apply.
Answer
This solution used pattern 8.
Other things to note
You can use a whole host of other formulas in this case to check this, but the | operator in regex allows you to make a much simpler formula when you are checking for multiple conditions in text.
Regex is case sensitive, so you will notice that we used Lower() to first ensure that our regex expression would catch any price/service in the text no matter how it was capitalized.



Done
Done
Determine whether or not a store is open or closed based of the presence of numbers in a string
Done

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.