A Naive Quoted-String Regex Truncates at the First Escaped Quote
My social card generator pulled each subtitle out of a TypeScript source file with subtitle:\s*"([^"]+)". The negated character class stops at the first " it meets, and it cannot tell an escaped inner quote from the closing delimiter.
Eleven of twelve subtitles had no inner quotes, so eleven cards were fine. The twelfth began From \"screenshot theater\", and its card rendered a subtitle of exactly two characters: From \. It shipped that way and I never saw it, because nobody opens their own social cards. I only found it when a freshness gate started recomputing card fingerprints from source and the truncation showed up as a mismatch.
Two things worth carrying: (?:[^"\\]|\\.)* is the correct shape for a quoted value that permits escapes, and an unescape step must follow, since the capture now contains literal backslashes. If a generator and its verifier both parse the same source, they must share one parser. Fix the regex in one and not the other and the fingerprints will never agree again.
// Wrong: [^"]+ halts at the backslash-escaped quote inside the value.
const NAIVE = /subtitle:\s*"([^"]+)"/;
// Right: consume either a non-quote non-backslash character, or any
// backslash-escaped pair, so escaped quotes stay inside the capture.
const ESCAPE_AWARE = /subtitle:\s*"((?:[^"\\]|\\.)*)"/;
export const unescape = (value) =>
value.replace(/\\(["\\nt])/g, (_, ch) =>
({ n: "\n", t: "\t" })[ch] ?? ch);
export function parseSubtitle(source) {
const match = source.match(ESCAPE_AWARE);
return match ? unescape(match[1]) : null;
}