Why this string matches the pattern ?
pattern = """
^Page \d of \d$|
^Group \d Notes$|
^More word lists and tips at http://wwwmajortests.com/word-lists$|
"""
re.match(pattern, "stackoverflow", re.VERBOSE)
According to me it should match strings like "Page 1 of 1" or "Group 1 Notes".
In your regular expression, there's trailing |:
# ^More word lists and tips at http://wwwmajortests.com/word-lists$|
# ^
Empty pattern matches any string:
>>> import re
>>> re.match('abc|', 'abc')
<_sre.SRE_Match object at 0x7fc63f3ff3d8>
>>> re.match('abc|', 'bbbb')
<_sre.SRE_Match object at 0x7fc63f3ff440>
So, Remove the trailing |.
BTW, you don't need ^ becasue re.match checks for a match only at the beginning of the string.
And, I recommend you to use raw strings(r'....') to correctly escape backslahes.
ADDITIONAL NOTE
\d matches only a single digit. Use \d+ if you also want to match multiple digits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With