-1
import re
greedyHaRegex = re.compile(r'(Ha){3, 5}')
mo1 = greedyHaRegex.search('HaHaHaHaHa')
mo1.group()
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    mo1.group()
AttributeError: 'NoneType' object has no attribute 'group'

I don't understand why this error occurred.

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149

1 Answers1

2

Your regex is not matching because of the extra space in the quantifier {3, 5}, thus search() returns None Remove the space and it and it will match. Use for example regex101 to debug such thing.

Guillaume
  • 5,497
  • 3
  • 24
  • 42