From f0585c30c3c79e47d8febb1dff59864ef117d79b Mon Sep 17 00:00:00 2001 From: Justin Oros Date: Thu, 14 May 2026 16:12:15 -0700 Subject: [PATCH] =?UTF-8?q?Fix=20letter=20replacement=20regex=20=E2=80=94?= =?UTF-8?q?=20only=20rewrite=20'Both=20X=20and=20Y'=20patterns,=20not=20st?= =?UTF-8?q?andalone=20letters=20in=20answer=20text?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/game.js b/game.js index ea4f019..44654a1 100644 --- a/game.js +++ b/game.js @@ -1088,8 +1088,17 @@ class Game { }); function rewriteLetterRefs(text) { - return text.replace(/\b([ABCD])\b/g, (match, letter) => { - return letterToSlot[letter] !== undefined ? letterToSlot[letter] : match; + /* Only rewrite letters that appear in explicit option-reference patterns: + "Both A and B", "A and B", "Both B and C", etc. + Never replace standalone A/B/C/D in regular sentence text. */ + return text.replace(/\bBoth ([ABCD]) and ([ABCD])\b/gi, (_, l1, l2) => { + const n1 = letterToSlot[l1.toUpperCase()]; + const n2 = letterToSlot[l2.toUpperCase()]; + return `Both ${n1 ?? l1} and ${n2 ?? l2}`; + }).replace(/\b([ABCD]) and ([ABCD])\b/g, (_, l1, l2) => { + const n1 = letterToSlot[l1]; + const n2 = letterToSlot[l2]; + return `${n1 ?? l1} and ${n2 ?? l2}`; }); }