Advertisement

Pattern library / Strings & Text

Regex to Match Any Word from a List

\b(?:error|warn|critical)\b finds whichever word from your list appears in the text. The \b boundaries are what make it safe: error fires only as a whole word, never inside errors or error_rate. Valid RE2, so the same pattern runs in GA4, BigQuery, Go and Rust.

The pattern
\b(?:error|warn|critical)\b
Load this pattern into the tester →

How the pattern works

Test it: match & no-match examples

Every row is loaded straight into the tester — click Try to see the match live:

InputResultWhy
timeout: critical failure upstreamMatchcritical matches as a whole wordTry →
everything completed with no issuesNo matchnone of the listed words appearTry →
an error occurred while parsingMatcherror matches between two word boundariesTry →
errors were counted in the reportNo match\b blocks the prefix match — errors is not errorTry →
ERROR: disk fullNo matchcase-sensitive by default; add the i flag to catch ERRORTry →
error_rate exceeded thresholdNo matchunderscore is a word character, so \b never fires inside error_rateTry →

Where to use it

JavaScript

const re = /\b(?:error|warn|critical)\b/g;
'retry failed: critical'.match(re);  // ['critical']

Python

import re
re.findall(r'\b(?:error|warn|critical)\b', 'an error occurred')  # ['error']

BigQuery / GA4 (RE2)

SELECT REGEXP_CONTAINS('retry failed: critical', r'\b(?:error|warn|critical)\b')

Common mistakes

Test this pattern on your own data
Paste it into the free tester with your real strings — nothing leaves your browser.
Open the regex tester →

FAQ

How do I match a list of words in a sentence?

Put every word in one group and wrap it in word boundaries: \b(?:error|warn|critical)\b. It finds any of the words anywhere in the text — swap in your own list and load it into the tester to check.

How do I check that a value is exactly one of the list?

Anchor the same group: ^(?:error|warn|critical)$. Without the anchors the pattern matches whenever the word merely appears somewhere inside the string.

Does this work in Google Analytics 4?

Yes — word boundaries, groups and alternation are all RE2 features, so this pattern runs in GA4, BigQuery, Go and Rust. Remember GA4 full-matches by default: drop the anchors for "contains any of these words", keep them for exact values.

Log Level Regex — Match INFO / WARN / ERROR Lines · Country Code Regex - ISO 3166 Alpha-2 / Alpha-3 · Hashtag Regex - Match #tags in Posts & Text

For GA4-specific patterns, see the GA4 regex cheat sheet, the page path regex guide, the event filter regex guide, the GA4 regex match types, the custom channel grouping guide and RE2 vs PCRE. Browse the full regex pattern library.