Courses/Regex & Text Processing

๐Ÿ” Regex & Text Processing

findall & sub

Extract every match or rewrite the string.

re.findall returns every non-overlapping match. re.sub replaces matches with a string or a function's result.

import re
print(re.findall(r"\d+", "a1 b22 c333"))         # ['1', '22', '333']
print(re.sub(r"\s+", "_", "hello   world  py"))  # hello_world_py
main.py
Output
Press Run to execute.
Expected output
[3, 5, 2]
10

Sign in to track your progress across lessons.