Regular Expressions in Python
Regex finds text patterns. import re. re.search looks anywhere. re.match looks at the start. re.findall returns all matches. re.sub replaces. \d is a digit. \w is a word character. Use a raw string r"\d{10}" for a 10-digit mobile so backslashes stay sane.
Fresher example: re.findall(r"\d+", "Asha 90 Ravi 85") → ['90', '85']. Don’t parse a mobile with ten if-checks when one pattern works. search vs match: match only at the beginning.
Regular Expressions in Python — output — True then True. 10 digits; Asha letters only.
re.search vs re.match if asked.