Regular Expression? A regular expression (regex) is a special string used to describe a pattern for searching or matching text. Think of it as a search formula for strings. 📦 The re Module Python has a built-in module called re for working with regular expressions. ✅ Importing: import re Common Functions in re Module Function Description re.match() Matches pattern at the beginning of string re.search() Searches pattern anywhere in string re.findall() Returns all matching substrings re.finditer() Returns iterator of matches re.sub() Replaces pattern with another string re.split() Splits string based on pattern re.compile() Compiles a regex pattern into an object Basic Pattern Examples Pattern Meaning . Any character except newline ^ Start of string $ End of string * 0 or more times + 1 or more times ? 0 or 1 time {m} Exactly m times {m,n} Between m and n times [...] Match any one of the characters \d Digit (0–9) \D Not a digit \w Word character (a-z, A-Z, 0-9, _) ...
Comments
Post a Comment