warl0ck warl0ck - 1 month ago 4x
Python Question

group name can't start with number?

It looks like I can't use regex like this one,


With re package it would raise and error,

sre_constants.error: bad character in group name u'74xxx'

It looks like I can't use group names that starts with a number, why?

P.S golang does not have such problem, so does many other languages


Given the doc:

Group names must be valid Python identifiers

As the variables, identifiers mustn't start with a number in Python. See more about identifiers here:

identifier  ::=     (letter|"_") (letter | digit | "_")*
letter      ::=     lowercase | uppercase
lowercase   ::=     "a"..."z"
uppercase   ::=     "A"..."Z"
digit       ::=     "0"..."9"