Your ticket pattern follows the team setting, and .test() says which commits have tickets. Each ticket line also needs the key and the title, though, and the team’s review bot counts every ticket a subject mentions. In Python, a match object handles the first job and re.findall() the second. In JavaScript, one method does both, and its “no match” result is where a finished-looking port breaks.
Read the Groups by Position
JavaScript’s .match() lives on the string and takes the pattern, the other way round from Python. Here’s how Python’s matching operations and results map to JavaScript:
| Python | JavaScript |
|---|---|
TICKET.match(subject), TICKET.search(subject) |
subject.match(TICKET) |
ticket[1] or ticket.group(1) |
ticket[1] |
ticket.start() |
ticket.index |
None for no match |
null for no match |
re.findall(pattern, subject), no groups |
subject.match(pattern), with g |
Watch out for Python’s order: TICKET.match(subject) stops with TypeError: TICKET.match is not a function. TICKET.exec(subject) keeps that order and gives the same result for a pattern without g, but most code calls .match() on the text. Like .test(), .match() searches anywhere, as re.search() does, so the ^ in TICKET makes .match() behave like Python’s re.match().
For a successful match without g, the result is an array with the whole match at [0] and the groups starting at [1]. Indexing carries over from Python, but there’s no group() method.
The .index offset counts UTF-16 code units, the units JavaScript uses to slice strings. Those offsets can differ from Python’s character positions beyond ASCII. That distinction is a later topic. The “no ticket” check ports line for line, with === null for is None: