Match the previous thing zero or more times
* is the most permissive quantifier. It says "the previous element, repeated 0 or more times." The critical word is zero — * ALWAYS matches, because matching nothing satisfies it.
Pattern colou*r matches color, colour, colouur, all the way to colouuuuuuuur. The u can repeat 0 or more times.
What 'previous element' means
* applies to the immediately preceding piece, which can be:
- A single character:
ab*matchesa,ab,abb,abbb... - A character class:
[0-9]*matches an empty string or any run of digits. - A group:
(ab)*matches an empty string,ab,abab,ababab...
The element to its LEFT — that's it. ab* repeats only the b, not ab.
The 'always matches' surprise
Because * matches zero occurrences, an unanchored pattern with only * always succeeds. re.match(r'\d*', 'hello') returns a match — an empty match at position 0. This is technically correct but rarely useful. Combine * with anchors or other elements that force at least something to match.