开发者

Determine if a group within a regex match is a number

开发者 https://www.devze.com 2023-04-13 09:44 出处:网络
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?

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

精彩评论

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