开发者

Determine if a group within a regex match is a number

If I have, for example, the below regex string:

'^/abc/(?P<some_int>\d{3})/\d{0,2}/$'  

Is there an easy way to determine when a group is a number/int?


I know that it is an int, but say this needed to be processed somewhere else and it needed to be deduced from just the m开发者_开发百科atch object.


m.group(WHICHEVER_YOU_WANT).isdigit()


You are matching it with \d{3} so it will match only if it is a number with three digits ( including leading zeroes)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜