Your lookbehind pulled 30 and 7 out of the refund note without the dollar signs. The helper’s last regex jobs are about ticket titles: check that each title carries a ticket key, and read the ticket numbers out of a merge ticket’s title, such as 2401 2402 2403. Both look routine, but a JavaScript regex can remember where it stopped, and that memory decides which titles pass.
In this lesson, you’ll see where a regex keeps that position and use it to scan a title piece by piece.
Reuse One Ticket Key Regex Across Titles
The team lead’s Python module compiles the key pattern once. It calls .search() to check each title and .finditer() to list a merge title’s keys:
import re
TICKET_KEY = re.compile(r"PAY-\d+")
titles = ["PAY-2401 refund fix", "PAY-2402 café receipts", "PAY-2403 refund approval"]
for title in titles:
print(bool(TICKET_KEY.search(title)))
print([m[0] for m in TICKET_KEY.finditer("Merge PAY-2401 PAY-2402 PAY-2403")])
Python prints True three times, then the three keys. The method decides whether you get one match or all of them, and the pattern needs no flag. JavaScript’s .matchAll(), by contrast, needs the g flag on the regex itself and refuses one without it:
"Merge PAY-2401 PAY-2402".matchAll(/PAY-\d+/);
JavaScript stops with a type error. This shortened output omits the source context and stack trace:
...
TypeError: String.prototype.matchAll called with a non-global RegExp argument
...
So the port keeps one regex, as Python does, and gives it g. The title check uses it too:
const ticketKey = /PAY-\d+/g;
console.log(ticketKey.test("PAY-2401 refund fix"));
console.log(ticketKey.test("PAY-2402 café receipts"));
console.log(ticketKey.test("PAY-2403 refund approval"));
Predict the three answers, then run it: