Your top_customers_by_mrr returns clean customer dicts. But sometimes names come from a raw JSON blob — logs, Zapier webhooks, or a copied Stripe payload. How do you extract just the names?
After top_customers_by_mrr I have clean dicts. But from raw text — like a pasted JSON string — I'd have to manually scan for 'name' fields. There's no structure I can parse directly.
re.findall extracts all matches of a pattern in one call. For a JSON-like string, the pattern r'"name":\s*"([^"]+)"' finds every "name": "..." and captures the value inside the quotes:
import re
text = '{"name": "Acme Corp", "mrr": 149}'
names = re.findall(r'"name":\s*"([^"]+)"', text)
print(names) # ['Acme Corp']What does ([^"]+) mean? The square brackets and the caret are confusing.
[^"] means 'any character that is not a double quote'. + means 'one or more'. Together [^"]+ matches any run of characters up to the next quote — exactly the value inside a JSON string. The parentheses () capture it. Here's the full function:
def extract_customer_names(raw_text: str) -> list:
import re
names = re.findall(r'"name":\s*"([^"]+)"', raw_text)
cleaned = [clean_customer_name(n) for n in names]
print(f"Extracted {len(cleaned)} names")
return cleanedSo I can paste a raw Stripe webhook payload and get a clean list of customer names in one function call. No JSON parsing, no manual scanning.
Regex is ugly — until it replaces 20 lines of manual string scanning. Then it's beautiful.
I just extracted and cleaned customer names from unstructured text. That works on webhook payloads, log files, any string.
re.findall returns all matches as a list — never crashes on zero matches, just returns []. re.search returns only the first match as an object. For extraction, findall is usually what you want.
re.findall(pattern, text) returns a list of all matches.
import re
re.findall(r'"name":\s*"([^"]+)"', text)| Token | Meaning |
|---|---|
[^"]+ | One or more non-quote characters |
\s* | Zero or more whitespace |
() | Capture group — what gets returned |
r'...' | Raw string — backslashes not escaped |
Always use raw strings (r'...') for regex patterns — \s means whitespace; without r, \s becomes an escape sequence in Python strings.
Your top_customers_by_mrr returns clean customer dicts. But sometimes names come from a raw JSON blob — logs, Zapier webhooks, or a copied Stripe payload. How do you extract just the names?
After top_customers_by_mrr I have clean dicts. But from raw text — like a pasted JSON string — I'd have to manually scan for 'name' fields. There's no structure I can parse directly.
re.findall extracts all matches of a pattern in one call. For a JSON-like string, the pattern r'"name":\s*"([^"]+)"' finds every "name": "..." and captures the value inside the quotes:
import re
text = '{"name": "Acme Corp", "mrr": 149}'
names = re.findall(r'"name":\s*"([^"]+)"', text)
print(names) # ['Acme Corp']What does ([^"]+) mean? The square brackets and the caret are confusing.
[^"] means 'any character that is not a double quote'. + means 'one or more'. Together [^"]+ matches any run of characters up to the next quote — exactly the value inside a JSON string. The parentheses () capture it. Here's the full function:
def extract_customer_names(raw_text: str) -> list:
import re
names = re.findall(r'"name":\s*"([^"]+)"', raw_text)
cleaned = [clean_customer_name(n) for n in names]
print(f"Extracted {len(cleaned)} names")
return cleanedSo I can paste a raw Stripe webhook payload and get a clean list of customer names in one function call. No JSON parsing, no manual scanning.
Regex is ugly — until it replaces 20 lines of manual string scanning. Then it's beautiful.
I just extracted and cleaned customer names from unstructured text. That works on webhook payloads, log files, any string.
re.findall returns all matches as a list — never crashes on zero matches, just returns []. re.search returns only the first match as an object. For extraction, findall is usually what you want.
re.findall(pattern, text) returns a list of all matches.
import re
re.findall(r'"name":\s*"([^"]+)"', text)| Token | Meaning |
|---|---|
[^"]+ | One or more non-quote characters |
\s* | Zero or more whitespace |
() | Capture group — what gets returned |
r'...' | Raw string — backslashes not escaped |
Always use raw strings (r'...') for regex patterns — \s means whitespace; without r, \s becomes an escape sequence in Python strings.
You receive Stripe webhook payloads as raw JSON strings and need to extract all customer names from them for your CRM log. Write `extract_customer_names(raw_text)` that uses `re.findall` to pull every `"name": "..."` value from the text and returns a list of cleaned names.
Tap each step for scaffolded hints.
No blank-editor panic.