+ 8
This code confuses me. How does it work although it's drastically changed?
2 Answers
+ 4
The way that re.match works is that it searches for a specific pattern within the string, in this case being spam, and returning true if it finds it anywhere within as a substring. This means that it doesn't have to be the entire string, but just apart of it.
+ 3
Code:
pattern = r'spam'
target = "spamsyxzytrdguytrzwxxx"
re.match(pattern, target)
Translation:
try to find in the beginning of target an 's' folowed by a 'p' then an 'a' and then a 'm'.