Courses/Regex & Text Processing

๐Ÿ” Regex & Text Processing

re.search & re.match

Find a pattern anywhere in a string.

Use re.search to find the first match anywhere, re.match to anchor at the start.

import re
m = re.search(r"\d+", "order 1234 shipped")
print(m.group())  # 1234

Common metacharacters: \d digit, \w word char, \s whitespace, + one-or-more, * zero-or-more, ? optional.

main.py
Output
Press Run to execute.
Expected output
555-1234

Sign in to track your progress across lessons.