问题
It looks like I can't use regex like this one,
(?P<74xxx>[0-9]+)
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
回答1:
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"
回答2:
If this is the pattern you are searching r'(?P<74xxx>[0-9]+)'
and you wanted to include ?
in your search pattern then you have to prepend \
with it since it is the special character in python. So your search pattern should be r'(\?P<74xxx>[0-9]+)'
.
来源:https://stackoverflow.com/questions/39332611/group-name-cant-start-with-number