DevKits

Extraction

Match a quoted string

Flags: g

Extract text between double quotes, handling escaped quotes inside.

Pattern

Regular expression

"(?:[^"\\]|\\.)*"

How it works

Matches a double-quoted string that may contain escape sequences like `\"` or `\\n`. Uses an alternation: non-quote/non-backslash, or a backslash followed by any character.

Matches

  • "hello"
  • "say \\"hi\\""
  • "line 1\nline 2"

Non-matches

  • "unterminated
  • no quotes

Common gotchas

This pattern is greedy and works line by line only if the string contains no unescaped newlines. For real code/JSON parsing, use a proper parser; regex-based string extraction breaks on edge cases.

Language snippets

JavaScript

const re = /"(?:[^"\\]|\\.)*"/g;

Python

re.findall(r'"(?:[^"\\]|\\.)*"', text)

Go

re := regexp.MustCompile(`"(?:[^"\\]|\\.)*"`)

Java

Pattern.compile("\"(?:[^\"\\\\]|\\\\.)*\"")

Frequently asked questions

What is the regex for quoted string?

The pattern "(?:[^"\\]|\\.)*" (flags: g) matches quoted string. Matches a double-quoted string that may contain escape sequences like `\"` or `\\n`. Uses an alternation: non-quote/non-backslash, or a backslash followed by any character.

What does this quoted string pattern match?

It matches strings like "hello", "say \\"hi\\"", "line 1\nline 2", but rejects "unterminated, no quotes.

How do I use this pattern in JavaScript, Python, Go, Java?

Ready-to-run snippets are provided for JavaScript, Python, Go, Java. Copy the one for your language from the Language snippets section — each wraps the same core pattern in that language's regex API.

What are common pitfalls with a quoted string regex?

This pattern is greedy and works line by line only if the string contains no unescaped newlines. For real code/JSON parsing, use a proper parser; regex-based string extraction breaks on edge cases.

Related patterns

Try this pattern in a tool

Try any pattern live in the Regex Tester