Eight flags, readable back as re.flags in the alphabetical order dgimsuvy.
| Flag | Property | Effect |
|---|---|---|
g |
global |
find all matches; exec and test start at lastIndex and update it |
y |
sticky |
match only at exactly lastIndex (no scanning forward); also updates it |
i |
ignoreCase |
case-insensitive comparison |
m |
multiline |
^ and $ also match at line breaks |
s |
dotAll |
. also matches line terminators |
u |
unicode |
match by code point; enables \u{…}, \p{…}, stricter syntax |
v |
unicodeSets |
superset of u: set operations, \q{…}, properties of strings |
d |
hasIndices |
adds indices (start and end offsets) to match results |
Three things interviewers look for:
gandymake the regex object stateful.lastIndexis an own data property thatexecandtestread and write. A failed match resets it to0, so reusing one/…/gobject across inputs gives alternating results. Withoutgory,lastIndexis ignored and never updated.uandvchange the unit of matching from UTF-16 code unit to code point, so.matches an astral character as one unit.vis the successor ofu: it adds set subtraction--, intersection&&, nested classes, and\q{abc}string literals, plus properties of strings such as\p{RGI_Emoji}.uandvtogether is aSyntaxError. Prefervin new code.- Inline modifiers
(?i:…),(?-i:…)applyi,morsonly inside the group (ES2025). Other flags cannot be toggled.