Intro
Extract text between two characters in Google Sheets using formulas and functions, including REGEXEXTRACT and MID, to manipulate and parse data efficiently.
Extracting text between two characters in Google Sheets can be a useful skill, especially when dealing with data that needs to be cleaned or parsed. This process can be achieved using various formulas and functions within Google Sheets. Here, we'll explore how to extract text between two characters using the REGEXEXTRACT function, which is part of Google Sheets' regex (regular expression) functions.
The importance of text extraction cannot be overstated, especially in data analysis and processing. Being able to accurately and efficiently extract specific parts of text strings can save a significant amount of time and reduce the likelihood of errors. Google Sheets, with its powerful functions and user-friendly interface, makes this task manageable even for those without extensive experience in programming or data manipulation.
When dealing with text data, it's common to encounter strings that contain specific information enclosed between certain characters. For instance, you might have a dataset where names are enclosed in parentheses or where specific codes are bracketed. Extracting this information can be crucial for further analysis or processing. Google Sheets provides a straightforward way to accomplish this through the use of regular expressions.
Understanding Regular Expressions (Regex)

Regular expressions are a sequence of characters that form a search pattern. They can be used to check if a string contains the specified search pattern. In the context of extracting text between two characters, regex provides a powerful and flexible way to define the pattern you're looking for.
Using REGEXEXTRACT Function

The REGEXEXTRACT function in Google Sheets is used to extract a substring from a string based on a regular expression pattern. The syntax of the REGEXEXTRACT function is:
REGEXEXTRACT(text, regular_expression)
text
is the string from which you want to extract the text.regular_expression
is the pattern you're looking for.
To extract text between two characters, say between "(" and ")", you can use the following regular expression pattern:
\(.*?\)
Here, \(
and \)
are used to match literal parentheses (since parentheses have a special meaning in regex), and .*?
matches any character (except a newline) between them in a non-greedy manner (meaning it stops at the first closing parenthesis it encounters).
Example Usage

Suppose you have the following text in cell A1:
Hello (world) this is a test.
To extract "world", you would use the formula:
=REGEXEXTRACT(A1, "\(.*?\)")
This formula extracts the text between the first "(" and the first ")" in the string.
Extracting Between Other Characters

The principle remains the same for extracting text between other characters. You simply need to adjust the regular expression pattern to match the characters you're interested in. For example, to extract text between "[" and "]", you would use:
=\[.*?\]
And to extract text between "{" and "}", you would use:
=\{.*?\}
Remember, some characters have special meanings in regex (like .
, *
, ?
, etc.), so if you're trying to match literal instances of these characters, you'll need to escape them with a backslash (\
).
Handling Multiple Instances

If your string contains multiple instances of text enclosed between the same characters, and you want to extract all of them, you might need to use the REGEXREPLACE function in combination with an array formula, or utilize Google Sheets' filtering capabilities along with regex.
For instance, to extract all instances of text between "(" and ")", you could use an array formula like this:
=REGEXEXTRACT(A1, "\(.*?\)")
Then, press Ctrl+Shift+Enter
(or Cmd+Shift+Enter
on a Mac) to make it an array formula. However, this will only return the first match. For multiple matches, consider using:
=REGEXEXTRACT(A1, "\(.*?\)", ROW(A1:A10))
Assuming your data is in column A, and you're extracting into column B, this formula would extract matches into separate rows.
Best Practices and Troubleshooting

- Test Your Regex: Before applying your regex pattern to a large dataset, test it on a small sample to ensure it's working as expected.
- Use Non-Greedy Matches: When extracting between characters, using
.*?
instead of.*
can help prevent your regex from matching too much text. - Escape Special Characters: Remember to escape special characters with a backslash (
\
) when you intend to match them literally.
If your regex isn't working, check that your pattern is correctly formatted and that you've escaped any necessary characters. Also, ensure that the text you're trying to extract doesn't contain newline characters, as .*?
does not match newlines.
Gallery of Regex Examples
Regex Examples Image Gallery










Frequently Asked Questions
What is the purpose of the REGEXEXTRACT function in Google Sheets?
+The REGEXEXTRACT function is used to extract a substring from a string based on a regular expression pattern.
How do I extract text between two characters using regex in Google Sheets?
+You can use the REGEXEXTRACT function with a pattern that matches the characters and the text between them. For example, to extract text between "(" and ")", use the pattern "\(.*?\)".
What does the `.*?` pattern mean in regex?
+`.*?` is a non-greedy match for any character (except a newline). It matches as few characters as possible before the next part of the pattern matches.
In conclusion, extracting text between two characters in Google Sheets is a valuable skill that can greatly enhance your data manipulation capabilities. By mastering the use of the REGEXEXTRACT function and understanding how to construct effective regular expression patterns, you can efficiently extract the information you need from complex text strings. Whether you're working with names, codes, or any other type of data, the ability to precision-extract text will make you more proficient in handling and analyzing data in Google Sheets. We invite you to share your experiences, ask questions, or provide tips on using regex in Google Sheets in the comments below.