Expressões regulares em 5 minutos
Literais, classes e quantificadores.
Expressões regulares em 5 minutos é uma aula grátis de NLP Academy no CoddyKit. Esta é a aula 1 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de NLP Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de NLP Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
A Tiny Language for Patterns
A regular expression is a tiny pattern language for matching text. Instead of one fixed word, you describe the shape of what you want to find.
Python Speaks Regex Too
Python uses the built-in re module for regex. Import it once and you can search, match, and extract patterns from any string.
import re
re.search("cat", "the cat sat")Literals: Exact Characters
The simplest pattern is a literal. The pattern dog matches the exact letters d, o, g, in that order, wherever they appear in your text.
search Finds the First Match
Use re.search to scan a string and return the first place your pattern appears, or None when nothing matches at all.
m = re.search("sat", "the cat sat")
print(m.group())Character Classes With Brackets
A character class in square brackets matches any one listed character. The pattern [abc] matches a single a, b, or c each time.
re.findall("[aeiou]", "hello")Handy Class Shortcuts
Some classes have shortcuts. \d matches any digit, \w matches word characters, and \s matches spaces. They save you a lot of typing. 😊
The Dot Matches Anything
The dot stands for any single character except a newline. So h.t matches hat, hit, and hot, but never the two-letter ht.
Quantifiers Repeat Patterns
A quantifier says how many times the part before it repeats. Add a plus for one or more, a star for zero or more.
re.findall("a+", "aaa banana")Exact Counts With Braces
Use braces for precise repetition. The pattern \d{3} matches exactly three digits in a row, perfect for area codes or short IDs.
re.findall("\d{3}", "call 911 now")Anchors Pin the Position
Anchors match a position, not a character. The caret means start of string and the dollar sign means end of string.
findall Returns Every Match
While search finds one match, re.findall returns a list of every match in the text, which is great for counting or extracting many items.
re.findall("\d+", "2 cats, 5 dogs")Quick Check
You want to match exactly three digits in a row. Which pattern fits?
Recap: Your Regex Toolkit
You met literals, classes, the dot, quantifiers, and anchors. With re.search and re.findall, you can already describe and find real patterns. 🎉
Perguntas Frequentes
A aula “Expressões regulares em 5 minutos” é grátis?
Sim — o texto completo de “Expressões regulares em 5 minutos” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de NLP Academy, atualize para CoddyKit PRO. O curso de NLP Academy inclui 4 aulas no total.
O que vou aprender em “Expressões regulares em 5 minutos”?
Literais, classes e quantificadores. Você pratica NLP Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar NLP Academy?
Nenhuma experiência prévia é necessária. NLP Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 1 de 4.
Quanto tempo leva a aula “Expressões regulares em 5 minutos”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de NLP Academy?
Sim. Cada aula de NLP Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Expressões regulares em 5 minutos
- Encontrando e-mails e URLs
- Grupos de captura e substituições
- Truques de tokenização com expressões regulares