Advertisement

Pattern library / Extract & Replace

Regex to Match Quoted Strings

Config files, CSV-ish logs and template code all wrap values in quotes. The trap: ".*" is greedy and happily runs from the first opening quote to the last quote on the line. The fix is a negated class that simply refuses to cross a quote of the same kind.

The pattern
"[^"]*"|'[^']*'
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
name="Ada Lovelace"Matchcaptures "Ada Lovelace"Try →
key='value with spaces'Matchsingle-quotedTry →
say "hi" then "bye"Matchfirst pair only (not greedy across)Try →
unquoted valueNo matchno quotes presentTry →
open "but never closedNo matchno closing quoteTry →
"mixed 'inner' quotes"Matchinner opposite quote fineTry →

Where to use it

JavaScript

const re = /"[^"]*"|'[^']*'/g;
'key="hello world"'.match(re);  // ["hello world"]

Python (allow escaped quotes)

import re
re.findall(r'"(\\.|[^"\\])*"', 'msg="she said \\"hi\\""')

BigQuery / GA4 (RE2)

REGEXP_EXTRACT(line, r'"([^"]*)"')  # group 1 = inner text

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 capture the text inside the quotes?

Wrap the inner class in a group: "([^"]*)" — group 1 is the content without the quote characters.

Why does ".*" match too much?

It is greedy: the . also matches quotes, so the engine takes the last quote on the line as the closer. [^"]* cannot do that by construction.

Does this handle escaped quotes?

The simple version no; use "(\\.|[^"\\])*" which lets a backslash-escaped character through while still stopping at an unescaped closing quote.

Extract Numbers from String — Regex + Examples · Log Level Regex — Match INFO / WARN / ERROR Lines · Remove Query Parameters with Regex (Replace Example)

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.