What is regular expressions in Python?
Answer
Python's re module provides regular expression support. Common functions: re.match(pattern, string) — matches only at the beginning. re.search(pattern, string) — searches anywhere in the string, returns Match object or None. re.findall(pattern, string) — returns list of all non-overlapping matches. re.finditer(pattern, string) — returns iterator of Match objects. re.sub(pattern, repl, string) — replace matches. re.split(pattern, string) — split by pattern. re.compile(pattern) — compile for reuse. Match groups: re.search(r"(\d+)-(\w+)", text).groups(). Flags: re.IGNORECASE, re.MULTILINE, re.DOTALL. Common patterns: \d (digit), \w (word char), \s (whitespace), .* (greedy any), .*? (lazy any). Always use raw strings (r"pattern") to avoid backslash escaping issues.