JS: 'aaa'.match(/a/g)
JS: 'aaa'.match(/a/) // without g
Py: re.findall(r'a', 'aaa') # global by nature
output
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.
global flagfind all matchesg flagmultiple matchesmatch all
Note Affects all literal characters and character classes in the pattern. [a-z] with the i flag will also match uppercase letters. Be aware that case-folding in Unicode can be surprising -- the German sharp s (ss) may match SS in some engines.
Note Changes ^ and $ from matching string start/end to matching line start/end. Does NOT change the behavior of \A and \Z in Python, nor does it affect how the dot treats newlines. Combine with g in JS for all line-start matches.
multiline flagm flagline by lineper line matchmultiline regex
Without s: no match (dot skips \n)
With s: "line1\nline2"
Note The s flag makes the dot (.) match newline characters too. Before this flag existed, the workaround was [\s\S] to match any character including newlines. The s flag was added to JS in ES2018.
dotall flags flagdot matches newlinesingle line modematch across lines
With u: emoji treated as single character
Without u: emoji seen as two surrogate code units
Note In JS, the u flag enables full Unicode matching: surrogate pairs are treated as single code points, and Unicode property escapes (\p{...}) become available. Python 3 handles Unicode by default. Always use the u flag in JS when dealing with international text or emoji.
JS: const re = /\d+/y;
re.lastIndex = 4;
re.exec('abc 123 xyz') // ["123"] (starts exactly at index 4)
re.exec('abc 123 xyz') // null (index 7 is a space, not a digit)
output
First exec: "123" at index 4
Second exec: null (must match exactly at lastIndex)
Note The y flag forces the match to start at lastIndex, unlike g which searches forward from lastIndex. Useful for building tokenizers/lexers where you need sequential, contiguous matching. No Python equivalent -- Python's re.match already anchors to the start.
sticky flagy flaglastIndextokenizerlexeranchored match
Note Allows whitespace and comments in the pattern for readability. Spaces and # comments are ignored unless escaped or inside a character class. No native JS equivalent, but you can concatenate strings or use template literals to achieve similar readability.