Pular para o conteúdo principal
Módulo 1 · Lição 2 de 42/32 no curso~10 min
Lições do módulo (2/4)

Aulas básicas: \d \w \s

Beyond literal characters, regex give you predefined classes: shortcuts for "any digit", "any word character", "any whitespace". They are the first step toward truly useful patterns.

QUERY LENGTH LIMIT EXCEEDED. MAX ALLOWED QUERY : 500 CHARS

Each one matches a single character. To match "one or more characters" you need quantifiers (+, in module 2), but we will use + right away because "find me all the numbers" is too useful to wait for.

Code
Pattern: \d+
Sample:  Ho 3 mele, 12 pere e 100 prugne.
            ^      ^^      ^^^

\d+ means one or more consecutive digits: it matches 3, 12 and 100 as three separate matches (with the g flag).

\w: word characters

\w is equivalent to [A-Za-z0-9_] (ASCII letters, digits, underscore). It does NOT include accents, Greek letters or emoji: for those you need Unicode property escapes (\p{L}, module 5).

Deep dive into basic classes and negations

QUERY LENGTH LIMIT EXCEEDED. MAX ALLOWED QUERY : 500 CHARS

Try it

Exercício#regex.m1.l2.e1
Tentativas: 0Carregando…

Extract every sequence of consecutive digits (numbers) from the text. Use the `\\d` class with the `+` quantifier.

Carregando editor…
Mostrar dica

\\d+ captures one or more digits. With the g flag you collect every match.

Solução disponível após 3 tentativas

Review exercise

Exercício#regex.m1.l2.e2
Tentativas: 0Carregando…

Find every 'word' in the text: a continuous sequence of word characters (`\\w+`).

Carregando editor…
Mostrar dica

\\w+ matches sequences of letters/digits/underscore. Punctuation is skipped.

Solução disponível após 3 tentativas

Additional challenge

Exercício#regex.m1.l2.e3
Tentativas: 0Carregando…

Find all sequences of one or more consecutive whitespace characters in the text (including spaces, tabs, and newlines).

Carregando editor…
Mostrar dica

Use the \\s class with the + quantifier to capture consecutive whitespace sequences.

Solução disponível após 3 tentativas