freecoding.school100% FREE · NO SIGNUP
Closure CavesISSUE #32 of 61

regex · flags · g · i · m · s · u · y

LambdaVSThe Mutator
Lambda saysRegex flags change matching: g (global), i (ignore case), m (multiline), s, u, y.

Append flags after the closing slash: g finds all matches (not just the first), i ignores case, m makes ^/$ match line starts/ends, s lets . match newlines, u enables full Unicode, y is sticky. g is the one you'll reach for most (with replaceAll-style replaces).

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleReplace all vowels case-insensitively using the g and i flags.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>const out='Hello World'.replace(/[aeiou]/gi,'*');
document.getElementById('o').textContent=out;</script></body></html>
▶ Open the interactive comic issue
‹ Regex · Pattern MatchingRegex · Groups · Capture · Backreference ›