
Image by Editor
Google Sheets’ QUERY function is a powerful tool for sorting, aggregating, and filtering data using SQL-like syntax. But sometimes — especially with text-heavy datasets like product SKUs, URLs, and survey responses — the built-in filtering logic isn’t flexible enough. It can’t filter based on patterns rather than exact matches. That’s where REGEXMATCH comes in; combining QUERY with REGEXMATCH becomes incredibly powerful. In this tutorial, we’ll show how to use Google Sheets’ QUERY function with REGEXMATCH for dynamic filtering.
Understanding the Core Idea
QUERY: This QUERY function is designed to filter structured data using column references like SELECT * WHERE A = ‘value’. This works well for numeric or categorical data, but it’s limited when you need partial or flexible text matching.
REGEXMATCH: The REGEXMATCH function checks whether text matches a regular expression pattern. It returns TRUE if the pattern is found anywhere in the text, and FALSE otherwise.
Note: In Google Sheets, the QUERY string uses the Visualization API query language. It doesn’t accept Sheets functions like REGEXMATCH() directly. The regex feature inside QUERY is the matches operator.
Let’s use some toy datasets of Product SKUs, survey responses, and web traffic to show the dynamic filtering.
Simple Pattern Filtering
Let’s filter specific SKUs. Suppose you want to extract only rows where the SKU starts with US. The basic QUERY approach using literal strings would fail here because you’d need to know all possible US SKUs in advance. With a regex pattern, you can express the “starts with” rule.
- Select a cell and insert the following formula
=QUERY(A:D, "SELECT * WHERE Col1 MATCHES '^US-'", 1)

This formula dynamically lists all SKUs that begin with “US-”. This kind of filtering becomes especially valuable when new SKUs are added to the sheet. As long as they follow the same naming pattern, your filtered list updates automatically.
Filtering Complex Text Patterns
Regular expressions allow for much more than just prefixes. What if you want all Electronics products from any region? Suppose you want to filter US Electronics specifically, not just all US products or all Electronics?
To do so, you can combine multiple requirements in a single pattern. Select a cell and insert the following formula.
=QUERY(A:D, "SELECT * WHERE Col1 MATCHES '^US-ELEC'", 1)
This pattern enforces both conditions simultaneously: it starts with US- and has ELEC immediately after.

Filtering Survey Responses
Let’s create a new dataset for survey responses to see how pattern matching works with free-text data.
Survey responses are notoriously difficult to analyze because they’re unstructured text. Pattern matching gives you a way to categorize them automatically.
Let’s find responses containing words like “great”, “amazing”, or “excellent” to extract the positive feedback.
- Select a cell and use the following formula
=QUERY(A:D, "SELECT * WHERE LOWER(B) MATCHES '.*(great|amazing|excellent|fantastic|love this|just what i needed).*'", 1)

Because the matches operator is case-sensitive, you can use the LOWER function to normalize the text before matching. The parentheses with pipe-separated words (great|amazing|excellent|fantastic|love this|just what i needed) create an OR condition that matches any of these words. Since column B is the Feedback column, this searches through all the feedback text to filter positive feedback.
You can use a similar formula to filter negative feedback. Select a cell and insert the following formula.
=QUERY(A:D, "SELECT * WHERE LOWER(B) MATCHES '.*(poor|disappointed|broke).*'", 1)

This formula returns the responses that mention quality issues or problems. Notice how powerful this combined approach is; you’re not searching for exact phrases, but for indicator words that suggest sentiment.
Combining REGEXMATCH with QUERY for Advanced Filtering
REGEXMATCH returns TRUE if a regex pattern matches anywhere in the text (partial match by default). To integrate it with QUERY, create a virtual array by appending a helper column with REGEXMATCH results, then filter where that column is TRUE. This method shines when matches falls short (e.g., needing inline flags or more complex logic).
Let’s filter URLs, which is particularly useful for analyzing web traffic or managing link collections.
To find all blog URLs, you can use a combination formula. Select a cell and insert the following formula.
=ArrayFormula(
QUERY(
{A1:D18, ARRAYFORMULA(REGEXMATCH(B1:B18, "(?i)blog"))},
"SELECT Col1, Col2, Col3, Col4 WHERE Col5 = TRUE
ORDER BY Col3 DESC ", 1))

This formula first constructs a virtual table including A1:D18 plus a 5th column made by ARRAYFORMULA(REGEXMATCH(B1:B18,”(?i)blog”)), which marks TRUE when the URL in column B contains “blog” (case-insensitive).
The QUERY function then keeps only rows where the 5th column is TRUE, returns the first four columns, and sorts by Col3 (Traffic) descending.
Dynamic Filtering with Cell References
The real power of combining QUERY and REGEXMATCH comes into play when you make the pattern dynamic. You can turn your QUERY into an interactive tool that updates based on user input.
Let’s set up a control panel in the sheet by putting “Search Pattern” in cell F2 and leaving G2 empty for user input.
=IFERROR( QUERY(A1:D,"SELECT * WHERE Col1 MATCHES '" & G2 & "'",1), "No rows matched" )
The ampersand operator joins strings, so this formula takes the first part of the query string “SELECT * WHERE Col1 MATCHES ‘”, inserts whatever value is in cell G2, and closes with the final quote mark “‘”. Now users can type any regex pattern in G2, and the results update automatically without touching the formula.

You can extend this concept to create sophisticated filtering interfaces. Add multiple input cells for different criteria, then combine them in your QUERY. For instance, cell G2 could contain a SKU pattern, H2 could contain a category, and I2 could contain a status. Your formula would then concatenate all these conditions together, giving users a flexible way to slice and dice the data.
Conclusion
By using the above steps and formulas, you can use Google Sheets’ QUERY function with REGEXMATCH for dynamic filtering. For users already comfortable with the QUERY function, pairing it with REGEXMATCH opens a new layer of flexibility. Whether you’re working with product codes, analyzing survey responses, or filtering URLs, pattern matching lets you describe what you’re looking for rather than listing every specific value. This is particularly powerful when dealing with large datasets or when the exact values you need to match might change over time.
As an existing QUERY function user, the next step is to use the toy data, apply the matches operator, and start experimenting with REGEXMATCH for dynamic filtering. After practicing the formulas, you’ll be filtering like a pro. Once you’re comfortable, replace the static range with a dynamic range and watch the same formula work on thousands of rows without slowing down.
