Obviously, 'Legal Leaves '
isn't going to match [a-z]+
, because it has two spaces in it, and spaces don't match the class [a-z]
.
If you want both spaces to be part of what you match, you want to add either an explicit space or a \s
to the class: ([a-z\s]+)([0-9]+)
.
If you want the first space to be part of what you match, but the second space to be treated as a separator, you need to make that explicit by adding whatever separator you want (a space, any whitespace, one or more whitespace characters, etc.) in between: ([a-z\s]+)\s+([0-9]+)
.
If you just want to match Leaves
, then you just want the separator, but you also want to use search
instead of match
: ([a-z]+)\s+([0-9]+)
.
But meanwhile, if you don't actually understand what you're doing with regular expressions, why are you even using one here? If your format is really as static as it seems to be, you can just do this:
>>> s = 'Legal Leaves 2017'
>>> s.rpartition(' ')
('Legal Leaves', ' ', '2017')