முக்கிய உள்ளடக்கத்திற்குச் செல்லவும்
eLearner.app
தொகுதி 7 · பாடம் 1 இன் 4பாடத்திட்டத்தில் 25/32~12 min
தொகுதி பாடங்கள் (1/4)

அனைத்து கொடிகளும் விரிவாக

Complete recap of all the flags available in modern JavaScript (ES2024). A flag is a single character that modifies the behavior of the regex; they can be combined in any order.

FlagNameEffect
gGlobalFinds all matches, not just the first (required for matchAll).
iIgnore caseCase-insensitive (incl. Unicode characters with the u/v flag).
mMultiline^ and $ match the start/end of a line, not just the string.
sDot allThe . also matches newline \n.
uUnicodeCorrect handling of code points > 0xFFFF and enables \\p{...}.
vUnicode v-modeModern extension of u with set operations ([abc&&[def]]).
yStickyMatches only from position lastIndex, no skipping.
dHas indicesThe result includes indices with start/end of each group.
JS
const re = /foo/gimu; // global + insensitive + multiline + unicode
re.flags; // "gimu" (always in canonical order: dgimsuvy)

Typical combinations

  • g + i -- "find everything, case-insensitive". 80% of practical uses.
  • g + m -- to match line by line in multiline text.
  • g + s -- "the dot matches anything, including newlines". Useful to extract blocks across multiple lines.
  • u (or v) -- always if you are dealing with real-world text in any language or emoji.

Unicode v-mode and flag evolution

The v flag (available in ES2024) replaces u and enables advanced operations on sets, such as character class intersection and subtraction (e.g. [\\p{White_Space}&&\\p{ASCII}]).

Try it

உடற்பயிற்சி#regex.m7.l1.e1
முயற்சிகள்: 0ஏற்றுகிறது…

Find all occurrences of 'ciao' regardless of case. Use the correct flag.

எடிட்டரை ஏற்றுகிறது…
குறிப்பைக் காட்டு

Add the i flag (case-insensitive) next to g.

3 முயற்சிகளுக்குப் பிறகு தீர்வு கிடைக்கும்

Review exercise

உடற்பயிற்சி#regex.m7.l1.e2
முயற்சிகள்: 0ஏற்றுகிறது…

Find a block between `<pre>` and `</pre>` even if it contains newlines. You must use the flag that makes the dot also match newlines.

எடிட்டரை ஏற்றுகிறது…
குறிப்பைக் காட்டு

Add the s flag so . matches newlines too, and use lazy .+? to stop at the first </pre>.

3 முயற்சிகளுக்குப் பிறகு தீர்வு கிடைக்கும்

Additional challenge

உடற்பயிற்சி#regex.m7.l1.e3
முயற்சிகள்: 0ஏற்றுகிறது…

Match sequences of ASCII characters, explicitly excluding digits, using Unicode v-mode properties (flag `v`) and set subtraction syntax `[\p{ASCII}--\p{Nd}]+`.

எடிட்டரை ஏற்றுகிறது…
குறிப்பைக் காட்டு

Use the v flag and write the set subtraction [\p{ASCII}--\p{Nd}]+ to exclude numbers.

3 முயற்சிகளுக்குப் பிறகு தீர்வு கிடைக்கும்