Text Processing Modules
re
Search, extract and replace text with regular expressions. compile() makes a reusable pattern; search() finds a match anywhere, whereas fullmatch() requires the entire input. Use raw string literals for patterns containing backslashes. Bound untrusted patterns and input sizes; backtracking can be expensive.
Formal Syntax & Structure
python syntaxpython
import reReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
import repattern = re.compile(r"[A-Z]{2}-\d{3}")print(pattern.findall("IDs: AB-123 and CD-456"))