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

How to specify repetitions Regex in Python?


The following code matches 3 As and 4 Bs pattern in the given string as follows

Example

import re
foo = 'AAABBBBBB'
match = re.search(r'A{3}B{4}', foo)
print match.group()

output

AAABBBB