GoConqr has a new look! Let us know what you think.

Module 9 of 10 · Text

Untitled

Brenda Gabriela Senra da Silva

Pattern: 

é a classe do Java usada para trabalhar com regex.

Ela representa:

um padrão de busca.

 

2. Pattern.compile(...)

transforma a regex em um objeto que o Java consegue usar.

É como:

“preparar” a regex.

 

3. A regex

"#\\w+"

é a regra de busca.

 

Como isso se conecta ao Matcher

Matcher matcher = pattern.matcher(text);

 

o Matcher pega:

  • a REGRA (pattern)
  • e o TEXTO (text)

e começa a procurar partes que combinem.

 

Fluxo

Regex define a regra
        ↓
Pattern guarda a regra
        ↓
Matcher aplica a regra ao texto
        ↓
find() procura ocorrências
        ↓
group() pega o trecho encontrado

 

Hierarquia

Pattern ↓ cria Matcher

Analogia simples

Imagine:

Pattern = molde/regra Matcher = pessoa usando o molde

O molde cria/orienta a busca.

Instructions

You must submit an attempt for this quiz to progress. You can submit it after the last question.

Go to the chosen module

Feedback

What is it about?

What do you think of the new look?

How do you like it?