正则表达式检查字符串是否为numb

2024-09-21 05:49:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个我认为是数字的值,但是我用来确认该值是数字的RegEx失败了。

我不确定这是值的错误还是正则表达式的错误,因为这个正则表达式在过去的情况下对我有用。

regnumber = re.compile(r"(\d),(\d) | (\d)")

print("final weight:", weight)

if regnumber.search(weight):
    print("weight = an int")

else:
    print("weight does not = int")

这段代码产生:

final weight: 7088                   
weight does not = int

有人能给我解释一下为什么我的RegEx失败了或者这不是一个数字吗?

谢谢。


Tags: researchif错误not情况数字regex

热门问题