Lições do módulo (1/4)
Todas as bandeiras em detalhes
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.
QUERY LENGTH LIMIT EXCEEDED. MAX ALLOWED QUERY : 500 CHARS
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(orv) -- 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
Find all occurrences of 'ciao' regardless of case. Use the correct flag.
Mostrar dica
Add the i flag (case-insensitive) next to g.
Solução disponível após 3 tentativas
Review exercise
Find a block between `<pre>` and `</pre>` even if it contains newlines. You must use the flag that makes the dot also match newlines.
Mostrar dica
Add the s flag so . matches newlines too, and use lazy .+? to stop at the first </pre>.
Solução disponível após 3 tentativas
Additional challenge
Match sequences of ASCII characters, explicitly excluding digits, using Unicode v-mode properties (flag `v`) and set subtraction syntax `[\p{ASCII}--\p{Nd}]+`.
Mostrar dica
Use the v flag and write the set subtraction [\\p{ASCII}--\\p{Nd}]+ to exclude numbers.
Solução disponível após 3 tentativas