Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Expressões Regulares para novatos, usando Python
Search
Amom Mendes
July 09, 2016
Programming
23
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Expressões Regulares para novatos, usando Python
Amom Mendes
July 09, 2016
Transcript
36 slides
Globalcode – Open4education Expressões Regulares para novatos, usando Python Amom
Mendes
Globalcode – Open4education Agenda • O que são expressões regulares
• Para que servem? • Metacaracteres • Notebook
Globalcode – Open4education Agenda • O que são expressões regulares
• Para que servem? • Metacaracteres • Notebook
Globalcode – Open4education Agenda • O que são expressões regulares
• Para que servem? • Metacaracteres • Notebook
Globalcode – Open4education Agenda • O que são expressões regulares
• Para que servem? • Metacaracteres • Notebook (talvez!)
Globalcode – Open4education Motivação
Globalcode – Open4education Motivação
Globalcode – Open4education O que são Expressões regulares?
Globalcode – Open4education O que são Expressões regulares? “Método formal
de especificar um padrão de texto” import re
Globalcode – Open4education O que são Expressões regulares? “Hoje tem
trilha de Python no TDC” Caracteres literais
Globalcode – Open4education O que são Expressões regulares? “Hoje tem
trilha de Python no TDC” re.search (r‘(?i) (python).*(tdc)) Caracteres literais Regra(Símb. + Carac. Fn. Especiais)
Globalcode – Open4education O que são Expressões regulares? “Hoje tem
trilha de Python no TDC” re.search (r‘(?i) (python).*(tdc)) ‘Python no tdc’ Caracteres literais Regra(Símb. + Carac. Fn. Especiais) Match (casou)
Globalcode – Open4education Para que servem? • Muita | Qualquer
coisa relacionada a busca de padrões de caracteres • Router de páginas (ex. django) • Datas / Horários • Nomes • E-mails • Web Scrapping • Consulta bancos de dados • Substituição de caracteres • Etc, etc
Globalcode – Open4education Por onde começar?
Globalcode – Open4education Metacaracteres • Principais . ? * +
^ $ | [ ] { } ( ) \
Globalcode – Open4education Metacaracteres • Simplificando ^$\b Representantes Quantificadores Âncoras
Outros . [ ][^] ?*+{ } \ | (..) \1
Globalcode – Open4education Metacaracteres . Método findall: retorna um lista
com textos casados ( ) • Representantes
Globalcode – Open4education Metacaracteres . re.findall(r'n.o', #Expressão 'não, nao, neo,
nso, nzo,nap')#String ['não', 'nao', 'neo', 'nso', 'nzo'] • Representantes
Globalcode – Open4education Metacaracteres [...] • Representantes
Globalcode – Open4education Metacaracteres re.findall (r'[naão]', 'não, nao, neo') ['n',
'ã', 'o', 'n', 'a', 'o', 'n', 'o'] • Representantes
Globalcode – Open4education Metacaracteres m = re.search(r'[0-9][0-9]:[0-9][0-9]', 'Cheguei as 11:00
horas no TDC hoje') m.group() • Representantes
Globalcode – Open4education Metacaracteres m = re.search(r'[0-9][0-9]:[0-9][0-9]', 'Cheguei as 11:00
horas no TDC hoje') m.group() Método search: testa se casou e retorna um objeto com informações do match ( ) • Representantes
Globalcode – Open4education Metacaracteres m = re.search(r'[0-9][0-9]:[0-9][0-9]', 'Cheguei as 11:00
horas no TDC hoje') m.group() 11:00 • Representantes
Globalcode – Open4education m = re.findall(r'[^A-z ]’, 'Cheguei as 11:
00 horas no TDC hoje') ['1', '1', ':', '0', '0'] Metacaracteres • Representantes
Globalcode – Open4education ? Metacaracteres • Quantificadores
Globalcode – Open4education re.findall (r'fala[r!]?', 'falar, fala!, fala') ['falar', 'fala!',
'fala'] Metacaracteres • Quantificadores
Globalcode – Open4education * Metacaracteres • Quantificadores
Globalcode – Open4education re.findall (r'Ah*!', 'Ah!, Ahhh!, Ahhhh!, Ahhhhhhhhh!') ['Ah!',
'Ahhh!', 'Ahhhh!', 'Ahhhhhhhhh!'] Metacaracteres • Quantificadores
Globalcode – Open4education .* re.findall (r'Ah.*!', 'Ah!, Ahhh!, Ahhhh!,A(h *
1000)!') 'Ah!, Ahhh!, Ahhhh!,A (h * 1000)!' Metacaracteres • Quantificadores
Globalcode – Open4education + if re.search(r'Ah+!', 'A!'): print (‘Casou’) else:
print (‘Não Casou’) Não Casou Metacaracteres • Quantificadores
Globalcode – Open4education { } Metacaracteres • Quantificadores
Globalcode – Open4education re.findall (r'Ah{1,3}!','Ah!, Ahhh!, Ahhhh!, Ahhhhhhhhh!') ['Ah!', 'Ahhh!']
Metacaracteres • Quantificadores
Globalcode – Open4education Metacaracteres • Ancoras
Globalcode – Open4education = fome! Metacaracteres • Ancoras
Globalcode – Open4education notebook
Globalcode – Open4education Obrigado!
[email protected]
Other Decks in Programming
See All in Programming
読みやすい!と評判(?)の発表の準備にかける私のこだわり
shoheimitani
0
170
Math.sumPreciseから学ぶ、ECMAScript仕様の数値の種類
syumai
0
710
Getting Started with Vibe Coding
miccheng
0
250
AIが生成したコードは読むべきか?抽象化設計とコードの品質保証 / abstraction-design-and-quality
minodriven
17
9.6k
Skills Are the New npm [AAIF Bengaluru, Nov 2026]
shivamsaraswat
0
140
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
180
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
150
DroidKnights 2026 Android A2UI Jetpack Compose 기반의 안전한 AI UI 렌더링 - 박제창
itsmedreamwalker
1
260
Rails初心者がパスキーを実装してみて大変だったこと
ktombow
0
240
AI Augmentation Techniques with Liberty
ivargrimstad
1
580
ruby/uri meets WHATWG
jinroq
0
170
Canvas 2D Context Next
petamoriken
0
530
Featured
See All Featured
ラッコキーワード サービス紹介資料
rakko
5
6M
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
590
Making Projects Easy
brettharned
120
6.9k
Navigating Weather and Climate Data
rabernat
0
600
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
610
AI: The stuff that nobody shows you
jnunemaker
PRO
12
1.3k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
580
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
620
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Docker and Python
trallard
47
4.3k