+ 1
special sequences
mport re pattern = r"(.+) \1" match = re.match(pattern, "word word word wrod") if match: print ("Match 1") match = re.match(pattern, "?! ?! ?! !? ?! !?") if match: print ("Match 2") match = re.match(pattern, "abc cde") if match: print ("Match 3") for the above code, i am getting the output match 1 match 2, is this regex only for two words only. i cant understand? if possible any of us can help me to understand
1 Respuesta
+ 2
It is regex for [starting from the beginning of the string] any sequence of characters, followed by a space, then the same sequence of characters.
"word word" will be matched because "word", space, "word" matched the pattern, same with "?! ?!". "abc cde" did not because no sequence of characters starting from the beginning of the string matched the pattern.