Regex for JSON String Literal
Matches a JSON-style double-quoted string with proper escape sequence handling.
Pattern
/^"([^"\\]|\\.)*"$/ Live Tester
Enter a string to test
Examples
✓ "hello world"
✓ "line\nbreak"
✓ "escaped \\quote"
✗ 'single quotes'
✗ no quotes
✗ "unterminated
Pattern Breakdown
^" — opening double quote
([^"\\]|\\.)* — any non-quote/non-backslash char, or a backslash followed by any char
"$ — closing double quote
Code Snippets
Javascript
const regex = /^"([^"\\]|\\.)*"$/;
regex.test('"hello world"'); // true Python
import re
pattern = r'^"([^"\\\\]|\\\\.)*"$'
bool(re.match(pattern, '"hello world"')) # True Php
$pattern = '/^"([^"\\\\]|\\\\.)*"$/';
preg_match($pattern, '"hello world"'); // 1 Related Patterns
Email Address /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ URL /^https?:\/\/(www\.)?[a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([a-zA-Z0-9()@:%_+.~#?&/=-]*)$/ Phone Number (International) /^\+?[1-9]\d{1,14}$/ Phone Number (US) /^\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/ Phone Number (EU) /^\+?[1-9][0-9]{0,3}[\s.-]?\(?[0-9]{1,5}\)?[\s.-]?[0-9]{1,5}[\s.-]?[0-9]{1,5}$/ IPv4 Address /^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/
Frequently Asked Questions
What is the regex for JSON String Literal?▾
The regex pattern for JSON String Literal is /^"([^"\\]|\\.)*"$/. Matches a JSON-style double-quoted string with proper escape sequence handling.
How do I use the JSON String Literal regex in JavaScript?▾
In JavaScript you create the pattern with a regex literal or the RegExp constructor and call .test() to check a string against it. A ready-to-copy example is shown in the Code Snippets section above, alongside Python and PHP versions.
What does the JSON String Literal pattern match?▾
It matches strings like "hello world"; it rejects strings like 'single quotes'. See the Examples section above for the full list of matching and non-matching cases.