g - Global Flag
RX · Flags & Modifierssyntax
JS: /pattern/g Python: (default for findall/sub)example
JS: 'aaa'.match(/a/g)
JS: 'aaa'.match(/a/) // without g
Py: re.findall(r'a', 'aaa') # global by natureoutput
With g: ["a", "a", "a"]
Without g: ["a"] (first match only)
Python findall: ['a', 'a', 'a']Note In JS, the g flag makes match() return all matches instead of just the first. Without g, match() returns the first match with capture groups. Python's re.findall and re.sub are inherently global. Use re.search for first-match-only behavior in Python.