Loading...
Loading...
Test Python regular expressions with live preview and explanations
\dAny digit (0-9)\d+ matches "42" in "Room 42"\wWord character (a-z, A-Z, 0-9, _)\w+ matches words\sWhitespace (space, tab, newline)a\sb matches "a b".Any character except newlinec.t matches "cat", "cot"[abc]Any of a, b, or c[aeiou] matches vowels[^abc]NOT a, b, or c[^0-9] matches non-digits[a-z]Any lowercase letter[A-Za-z] matches letters*0 or moreab* matches "a", "ab", "abbb"+1 or moreab+ matches "ab", "abbb" but not "a"?0 or 1 (optional)colou?r matches "color", "colour"{n}Exactly n times\d{4} matches "2024"{n,m}Between n and m times\d{2,4} matches "99", "999"{n,}n or more times\d{3,} matches 3+ digits^Start of string^Hello matches "Hello World"$End of stringworld$ matches "Hello world"\bWord boundary\bcat\b matches "cat" not "cats"(abc)Capture group(\d+)-(\d+) captures both numbers(?:abc)Non-capturing group(?:Mr|Ms)\.\s\w+a|ba OR bcat|dog matches eitherre.findall() - Find ALL matches, return listre.search() - Find FIRST match anywherere.match() - Match at START of string onlyre.sub() - Replace all matches