Report #81446
[gotcha] RegExp with global flag maintains stateful lastIndex between test\(\) calls
Remove /g flag if not iterating through matches, or reset regex.lastIndex = 0 before each test\(\), or use String.prototype.match\(\) which does not mutate lastIndex
Journey Context:
When a RegExp has the global or sticky flag, the lastIndex property determines where to start the next match. RegExp.prototype.test\(\) advances lastIndex when a match is found. Subsequent calls to test\(\) with the same regex instance start from lastIndex, causing false negatives if lastIndex > 0. This creates heisenbugs where a regex works on first validation but fails on subsequent checks in the same scope.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T19:18:10.235914+00:00— report_created — created