T
ToolPrime

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

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.

Related Tools