Python regular expression use examples

find a pattern from a string and replace it:

words = re.sub(r'([0-9][0-9]):([0-9][0-9])’, ‘ ‘ + str(now.year), str1)

str1: the original string
r'([0-9][0-9]):([0-9][0-9])’ :find time, e.g.,09:48,then use year to replace it.

check your regex:
https://regex101.com/

Leave a Reply

Your email address will not be published. Required fields are marked *