🔍Regex Recipes

Extract Text Between Quotes

Extract content between double quotes with greedy vs lazy matching examples.

Pattern

"([^"]*)"

Explanation

Captures text between double quotes. Use lazy quantifier (.*?) for greedy matching across multiple quoted strings.

Examples

Single quoted
Input
The "quick brown" fox
Output
Captures: quick brown
Multiple quotes
Input
"first" and "second"
Output
Captures: first, second
Empty quotes
Input
Empty ""
Output
Captures: (empty string)
No quotes
Input
Plain text
Output
No match

Code Examples

JavaScript
// Extract all quoted strings
const text = 'He said "hello" and she said "world"';
const quotedStrings = text.match(/"([^"]*)"/g)
  .map(s => s.slice(1, -1)); // Remove quotes
// Result: ['hello', 'world']

// With capturing group
const matches = [...text.matchAll(/"([^"]*)"/g)];
const captured = matches.map(m => m[1]);

Try it Now

💡 Tips

  • Use [^"] to match anything except quotes
  • For both single and double quotes: ["']([^"']*)["']
  • Handle escaped quotes: "([^"\\]|\\.)*"
  • Use capturing groups to get content without quotes

⚠️ Common Pitfalls

  • Does not handle escaped quotes within strings
  • Assumes double quotes only (not single quotes)
  • Greedy matching can capture too much
  • Does not handle nested quotes