AI Workshop: learn to build apps with AI →
Regular Expressions: Flags

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


You can use the following flags on any regular expression:

  • g: matches the pattern multiple times
  • i: makes the regex case insensitive
  • m: enables multiline mode. In this mode, ^ and $ match the start and end of each line. Without it, they match only the beginning and end of the whole string.
  • u: enables support for Unicode (introduced in ES6/ES2015)
  • s: short for single line, it causes the . to match newline characters as well

Flags can be combined, and they are added at the end of the pattern in regex literals:

/hey/ig.test('HEy') //✅

or as the second parameter of the RegExp constructor:

new RegExp('hey', 'ig').test('HEy') //✅

Lessons in this unit:

0: Introduction
1: Introduction
2: Anchoring
3: Match Items in Ranges
4: Matching a Range Item Multiple Times
5: Negating a Pattern
6: Meta Characters
7: Regular Expressions Choices
8: Quantifiers
9: Optional Items
10: Groups
11: Capturing Groups
12: Using match and exec Without Groups
13: Noncapturing Groups
14: ▶︎ Flags
15: Inspecting a Regex
16: Escaping
17: String Boundaries
18: Replacing
19: Greediness
20: Lookaheads
21: Lookbehinds
22: Unicode
23: Unicode Property Escapes
24: Examples