AttributeError: 'NoneType' object has no attribute 'group'

Sometimes, this problem appears:

AttributeError: ‘NoneType’ object has no attribute ‘group’ or

TypeError: ‘NoneType’ object is not iterable

Sometimes its OK, in

https://share.streamlit.io/luiscarloseiras/gpt-2pt/main/gpt-2.py