What is difference between '.' , '?' and '*' in Python regular expression?


Special character dot '.'

(Dot.) In the default mode, this matches any character except a newline. If the DOTALL flag has been specified, this matches any character including a newline.

Special character '?'

Causes the resulting RE to match 0 or 1 repetitions of the preceding RE. ab? will match either ‘a’ or ‘ab’

Special character asterisk'*"

Causes the resulting RE to match 0 or more repetitions of the preceding RE, as many repetitions as are possible. ab* will match ‘a’, ‘ab’, or ‘a’ followed by any number of ‘b’s.


Updated on: 30-Jul-2019

266 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements