I\'m just learning Python, and I can\'t seem to figure out regular expressions.
r1 = re.compile(\"$.pdf\")
if r1.match(\"spam.pdf\"):
print \'yes\'
else:
The regular expression $.pdf
says "find the end of the string, then find any character and beyond the any character beyond the end of the string, find a p, a d and an f".
As written, it cannot sensibly match anything.
However, pdf$
would match.
In this specific case, you probably also want to do a search
rather than match
, as I believe match is inherently anchored at the start of the string.