Describing text patterns
Regular expressions are compact pattern languages for searching and transforming text. Python's re module supports matching, searching, replacement, splitting and captured groups.
Raw strings make patterns easier to read
Regex uses backslashes for its own syntax, while Python strings also use backslashes for escaping. Raw strings such as r'\d+' make many patterns easier to understand.
Regex is not a universal parser
Regex works well for simple structured patterns, but HTML, programming languages and deeply nested formats generally require dedicated parsers. Patterns applied to untrusted input should also be designed to avoid excessive backtracking.
Practice: validate a simple product code such as PROD-1234 using fullmatch().