What are regular expression repetition cases in Python?

PythonServer Side ProgrammingProgramming

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


raja
Published on 03-Jan-2018 11:43:12
Advertisements