Regex patterns/Text & extraction

Quoted string with escapes

The unrolled loop — matches "a \"quoted\" string" without catastrophic backtracking.

/"[^"\\]*(?:\\.[^"\\]*)*"/g
Open it in Rex

The problem

Match a double-quoted string that may contain escaped quotes, without stopping at the first escaped one.

How it reads

"[^"\\]repeatskipgroup\\any char[^"\\]repeatskiprepeatskip"

Follow the line from left to right — every path you can trace is a string this pattern matches.

  1. "[^"\\]*(?:\\.[^"\\]*…In order:
  2. "The character """
  3. [^"\\]*Any character except """ or "\", any number of times, including none, as many as possible
  4. (?:\\.[^"\\]*)*Repeated any number of times, including none, as many as possible:
  5. (?:\\.[^"\\]*)Group (not captured):
  6. \\.[^"\\]*In order:
  7. \\The character "\"
  8. .Any character (except a line break, unless the s flag is set)
  9. [^"\\]*Any character except """ or "\", any number of times, including none, as many as possible
  10. "The character """

Matches

  • "hello"
  • a "quoted" string
  • "with \"escapes\" inside"

Does not match

  • no quotes here
  • 'single quoted'

Where it bites

  • The shape is deliberate: "normal* (special normal*)*" — each character can be consumed in exactly one way, so a failure cannot be retried a different way. That is what makes it linear.
  • The tempting "(\\.|[^"])*" version has two branches that can both match the same character, which is the overlapping-alternatives ReDoS shape. Paste it into the tool and watch the step count.
  • It does not handle single quotes or template literals — add branches if you need them.

More text & extraction patterns