组名不能以数字开头? [英] group name can't start with number?

查看:41
本文介绍了组名不能以数字开头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来我不能像这样使用正则表达式,

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 没有这个问题,很多其他语言也没有这个问题

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

推荐答案

鉴于 doc:

组名必须是有效的 Python 标识符

Group names must be valid Python identifiers

作为变量,标识符在 Python 中不能以数字开头.在此处查看有关标识符的更多信息:

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"

这篇关于组名不能以数字开头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆