Computer >> Computer tutorials >  >> Programming >> Python

What are regular expression repetition cases in Python?


Things become more interesting when you use + and * to specify repetition in the pattern

• + -- 1 or more occurrences of the pattern to its left, e.g. 'i+' = one or more i's

• * -- 0 or more occurrences of the pattern to its left

• ? -- match 0 or 1 occurrences of the pattern to its left

Example

The following code answers the question above

import re
s = "sheeeeeeeeple"
match = re.search(r"he+", s)
print match.group()

Output

This gives the output

heeeeeeee