Start free · Free tools · Fair usage limits
Browse Tools

Categories

Custom AI Solutions – AI2Flows
LIVE NEWS
Loading latest AI & SEO news…
Home›Tools›Regex Tester›Regex: Text in double quotes
Regex pattern · find & extract

Regex: Text in double quotes

Regex to match text between quotes: a tested pattern with examples, a plain-English breakdown, and code for JavaScript, Python, PHP, Java and Go.

Quick answer

Use /"([^"]*)"/g with the global flag to find every match. In "He said "hi" and then "bye"." it finds ""hi"", ""bye"". Escaped quotes ("say \"hi\"") are not handled; use "((?:[^"\\]|\\.)*)" for that.

Last updated · Maintained by FreeAIToolz · How we test

/"([^"]*)"/g

2 match(es)

He said "hi" and then "bye".
Open in the full Regex Tester (replace, flags, groups) →

How this regex works

PartMeaning
"opening quote
([^"]*)group 1: everything up to the next quote
"closing quote

Flags: g finds every match instead of stopping at the first.

Examples

InputMatches
He said "hi" and then "bye"."hi", "bye"

Every example above is checked automatically in JavaScript and Python each time the site is built.

Limitations and edge cases

Escaped quotes ("say \"hi\"") are not handled; use "((?:[^"\\]|\\.)*)" for that. Curly quotes “ ” need their own characters.

When to use this pattern

Extracting quoted phrases, CSV fields or string literals in simple cases.

Use it in your language

JavaScript

const matches = text.match(/"([^"]*)"/g) ?? [];

Python

import re
matches = [m.group(0) for m in re.finditer(r'"([^"]*)"', text)]

PHP

preg_match_all('~"([^"]*)"~', $text, $m);
$matches = $m[0];

Java

Matcher m = Pattern.compile("\"([^\"]*)\"").matcher(text);
while (m.find()) { System.out.println(m.group()); }

Go

re := regexp.MustCompile(`"([^"]*)"`)
matches := re.FindAllString(text, -1)

More regex patterns

Frequently asked questions

What is the regex for Text in double quotes?
/"([^"]*)"/g. Escaped quotes ("say \"hi\"") are not handled; use "((?:[^"\\]|\\.)*)" for that. Curly quotes “ ” need their own characters.
Which languages does this pattern work in?
It is tested in JavaScript and Python and uses syntax that also works in PHP (PCRE) and Java. It also works in Go’s RE2 engine.
How do I replace the matches?
In JavaScript use text.replace(/"([^"]*)"/g, "replacement"); in Python use re.sub(r'"([^"]*)"', "replacement", text).