re.findall() returns every non-overlapping match for a regular-expression pattern. With capture groups, it returns matching groups as tuples in parenthesis order. section 17.1.1 section 17.5
A practical extraction pattern:
- Use `re.findall('(<([^<>]+)>)', text)` to find angle-bracketed placeholders while capturing both the complete placeholder and its inner name. section 17.1.1
- Iterate with `for placeholder, name in matches:` to unpack each two-tuple and build prompts or other processing steps. section 17.1.1
Extracting Mad Libs placeholders
For `The quick <adjective> <noun> jumps <preposition> the lazy <noun>.`, the call returns `[('<adjective>', 'adjective'), ('<noun>', 'noun'), ('<preposition>', 'preposition'), ('<noun>', 'noun')]`. section 17.1.1
>>> from pprint import pprint
>>> matches = re.findall('(<([^<>]+)>)', text)
>>> pprint(matches)
[('<adjective>', 'adjective'),
('<noun>', 'noun'),
('<preposition>', 'preposition'),
('<noun>', 'noun')]
Inspect the complete interactive output showing every extracted placeholder and its captured name. section 17.1.1

