How can I match it or any other string consisting of only lowercase letters and optionally ending with an asterisk?
This will do the following:
re.match(r"^[az]+[*]?$", s)
^
matches the beginning of a line.[az]+
matches one or more lowercase letters.[*]?
matches zero or one asterisk.$
matches the end of a line.
Your original regular expression matches only one lowercase character, followed by one or more asterisks.
source share