Source code for Python Tutorial for Beginners #26 - Regular Expressions.
regex_basics.py—re.search(),re.match(),re.findall(), raw strings, metacharacters (\d,\w,\s)patterns_groups.py— Character classes, quantifiers, capturing groups, named groups,re.sub(),re.compile()text_processor.py— Mini project: email validation, phone extraction, log parsing, text cleanup
python3 regex_basics.py
python3 patterns_groups.py
python3 text_processor.py- The
remodule for pattern matching re.search()to find patterns anywhere in textre.match()to check the start of a stringre.findall()to extract all occurrences- Raw strings (
r"...") to keep backslashes literal - Metacharacters:
\d,\w,\s,.,^,$ - Character classes
[a-z]and negation[^0-9] - Quantifiers:
*,+,?,{n},{n,m} - Capturing groups
()and named groups(?P<name>...) re.sub()for substitutionre.compile()for reusable patterns