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
22
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
Proxmox x Talos Linux x Terraform で実現するなんかいい感じの Kubernetes クラスタ / A Sleek Kubernetes Cluster Powered by Proxmox, Talos Linux, and Terraform
nnaka2992
0
260
Secure Your Coding Agent Like It’s Malware (v1.5) 🇬🇧 @Code.talks 2026
richargh
0
180
Web3Dライブラリを作ってVue Custom Rendererの仕組みを理解しよう / lets learn vue custom renderer by making 3d library
drumath2237
1
140
AI時代のFlutter品質設計 — アプリ品質を守るQuality Layers
omatty198
0
390
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
150
Crash Auto Pipelines
veronikapj
1
430
手の動かし方がわからなかった私が個人開発者になるまで
usagi0920_pochi
0
270
あなたはMCPの機能を、まだ知らない。
4geru
1
660
TS 7.0 で baseUrl が使えなくなった今、パスエイリアスをどうするか
bicstone
2
720
テストだけで見つかる? Rubyでつくるメソッド発掘器
izawa
0
140
なぜ私たちは「現時点では」KMPの導入を見送ったのか
chigichan24
1
300
Python Lambdaにおけるテストしやすい設計とAI支援の活用 / Designing Testable Python Lambda Functions with AI
kitano_yuichi
1
340
Featured
See All Featured
Mind Mapping
helmedeiros
1
440
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.5k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.4k
For a Future-Friendly Web
brad_frost
184
11k
ラッコキーワード サービス紹介資料
rakko
5
5.9M
Git: the NoSQL Database
bkeepers
PRO
433
67k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
490
Code Review Best Practice
trishagee
74
20k
Building Adaptive Systems
keathley
44
3.3k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
48k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
580