Given the following string:
s = 'abcdefg*'
How can I match it or any other string only made of lowercase letters and optionally ending with an asterisk? I thought the following would work, but it does not:
re.match(r"^[a-z]\*+$", s)
It gives None and not a match object.
The following will do it:
^matches the start of the string.[a-z]+matches one or more lowercase letters.[*]?matches zero or one asterisks.$matches the end of the string.Your original regex matches exactly one lowercase character followed by one or more asterisks.