Meaning
Returns a list of all non-overlapping ASCII letter sequences found in a string. Solves the problem of extracting pure alphabetic tokens from text contaminated with punctuation, digits, or symbols. Reach for this when you need lightweight word tokenization that deliberately excludes non-letter characters.
Primary Function
String processing / Text extraction
Communicative Purpose
Enables isolation of alphabetic words from mixed text for downstream processing or filtering.
Pattern
re.findall(r'[A-Za-z]+', input_string)
Core Structure
re.findall(r'[A-Za-z]+', ...)
Função primária
String processing / Text extraction
Propósito comunicativo
Enables isolation of alphabetic words from mixed text for downstream processing or filtering.
Situações de gatilho
Data cleaning: extracting alphabetic tokens from noisy user input; NLP preprocessing: tokenizing words while discarding punctuation and digits; Coding challenges: parsing letter-only words from formatted strings
Contextos
Common in data cleaning scripts, log analysis, simple NLP preprocessing, and coding challenges.
Padrão
re.findall(r'[A-Za-z]+', input_string)
Estrutura central
re.findall(r'[A-Za-z]+', ...)
Slots de substituição
input_string: str
Colocados típicos
- Often used with list comprehensions
- str.join
- or re.sub for further processing.
Substituições comuns
- Using re.finditer for iterator – lazy
- memory‑efficient for large texts
- using str.split with regex – simple but may produce empty strings for consecutive delimiters
- using regex pattern '[^\W\d_]+' to include underscore – matches words with underscore while still excluding punctuation.
Erros comuns
Forgetting to import re → NameError: name 're' is not defined; using a normal string instead of a raw string → escape sequences are misinterpreted, causing pattern errors; expecting Unicode letters beyond ASCII → accented characters are silently omitted from results.
Similar / contraste
re.split(r'\\W+', text) splits on non-word characters; re.match checks start of string.
Interferências
Coming from JavaScript: \w matches digits and underscore by default → use [A-Za-z] to restrict to ASCII letters only
Família do chunk
- regular expressions
- re module functions
Nuance
Avoid when you need Unicode letter support since accented characters are silently omitted. For large strings, re.findall materializes the full result list in memory; use re.finditer for an iterator instead. Contractions like "isn't" split into ["isn", "t"], which may not match intended tokenization.
Efeito pragmático
Enables concise extraction of all matches for further processing.
Dica de memória
Think of re.findall as dragging a net through a string to catch every matching fish.
Nota
Returns a list of all non-overlapping matches of the pattern in the string.
Upgrade path
Learn to use re.compile for repeated patterns or re.finditer for iterator-based results.
Log in to save chunks.