Regex for quoted string

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

Options
Matches

Examples

Note

Handles escaped quotes inside the string: a backslash and any character count as one unit.

Matches in the example

  • "\"hello\""
  • "\"she said \\\"hi\\\"\""

Token by token

  1. " the character “"”
  2. (?: a group, not capturing
  3. [^"\\] any character except “"” or the character “\”
  4. | or
  5. \\ the character “\”
  6. . any character except a line break
  7. )* end of group, whole group zero or more times, as many as possible
  8. " the character “"”

Other patterns