lundi 15 mai 2017

about pattern pattern = r"(.+) \1" and pattern = r"(.+) \2" in python [duplicate]

This question already has an answer here:

Can you please explain these pattern for me? pattern = r"(.+) \1" and pattern = r"(.+) \2"

when i use the following script, there is no problem:

import re
pattern = r"(.+) \1"
match = re.match(pattern, "word word")
if match:
   print ("Match 1")

but when i change the pattern to r"(.+) \2" it rise an error. please explain exactly what is this pattern mean.

import re
pattern = r"(.+) \2"
match = re.match(pattern, "egg egg egg")
if match:
   print ("Match 1")

Aucun commentaire:

Enregistrer un commentaire