Loading lesson path
Flags are parameters that can modify how a regex pattern is used, such as making it case-insensitive or global./pattern/ flags
/d Performs substring matches (new 2022) /g Performs a global match (find all) /i
/m
/s Allows . (dot) to match line terminators (new 2018) /u Enables Unicode support (new 2015) /v
Formula
An upgrade to the /u flag for better Unicode support (new 2025)/y Performs a "sticky" search (new 2015)
Formula
Flag Syntax: /pattern/flags/
Regular expression (a search criteria) /
Formula
RegExp /g Flag (Global)/g flag matches all occurrences of the pattern, rather than just the first one.
A global search for "is" in a string:
let text = "Is this all there is?";
const pattern = /is/g;
let result = text.match(pattern);Formula
RegExp /i Flag (Insensitive)Formula
/i flag makes the match case - insensitive: /abc/i matches "abc", "AbC", "ABC".Formula
A case - insensitive search for "w3schools" in a string:let text = "Visit W3Schools";
const pattern = /is/g;
let result = text.match(pattern);Formula
RegExp /d Flag/d flag specifies the start and the end of a match.
Match every sub text that starts or ends with aa or bb:
let text = "aaaabb";
const pattern = /(aa)(bb)/d;
let result = text.match(pattern);Formula
RegExp /s Flag (Single line/DotAll)/s flag allows the . (dot) metacharacter to match newline characters (\n) in addition to any other character.
Formula
Without the /s flag, \n does not match . (wildchars):let text = "Line\nLine.";
const pattern = /Line./gs;
let result = text.match(pattern);/y flag performs a "sticky" search from the lastIndex property of the RegExp object.
/y flag lets a match start at the exact position where the last match ended.
Examples let text = "abc def ghi";
const pattern = /\w+/y;
// Start match from position 4 pattern.lastIndex = 4;
let result = text.match(pattern);Formula
The /y flag must be set to allow match from a position.let text = "abc def ghi";
const pattern = /\w+/;
// Start match from position 4 pattern.lastIndex = 4;
let result = text.match(pattern);/\w+/.
/\w+/ is "mach any word". You will learn more about metacharacters in the next chapters.
Formula
RegExp /u Flag (Unicode)