diff --git a/src/apps/review/src/lib/utils/metadataMatching.ts b/src/apps/review/src/lib/utils/metadataMatching.ts index aa18006f1..2279bfe00 100644 --- a/src/apps/review/src/lib/utils/metadataMatching.ts +++ b/src/apps/review/src/lib/utils/metadataMatching.ts @@ -113,13 +113,13 @@ export function findMetadataPhaseMatch( } // Replace all sequences of space, underscore, or hyphen in the target with a placeholder - const WORDSEP_PLACEHOLDER = '__WORDSEP__'; - const sepPattern = /[ \-_]+/g; - const targetWithPlaceholder = target.replace(sepPattern, WORDSEP_PLACEHOLDER); + const WORDSEP_PLACEHOLDER = '__WORDSEP__' + const sepPattern = /[ \-_]+/g + const targetWithPlaceholder = target.replace(sepPattern, WORDSEP_PLACEHOLDER) // Properly escape ALL regex metacharacters (including backslash), leaving the placeholder intact const escapedTarget = escapeRegexLiteral(targetWithPlaceholder) - .replace(new RegExp(escapeRegexLiteral(WORDSEP_PLACEHOLDER), 'g'), '[-_\\s]+'); - const sepInsensitive = new RegExp(`\\b${escapedTarget}\\b`); + .replace(new RegExp(escapeRegexLiteral(WORDSEP_PLACEHOLDER), 'g'), '[-_\\s]+') + const sepInsensitive = new RegExp(`\\b${escapedTarget}\\b`) if (sepInsensitive.test(normalizedMetadata)) { return { source: 'stringBoundary' } }