我正在学习regex,所以我尝试使用regex来验证给定输入的正确整数和十进制数,并带有/不带正/减号。
我在python中创建了regex:
([+-]?[0-9]+\.[0-9]+)|([+-]?[5-9]+)
但它不能正常工作。它的展示
# expecting left side expression of pipe-sign is running
re.search("([+-]?[0-9]+\.[0-9]+)|([+-]?[5-9]+)","1.1") # true correct
re.search("([+-]?[0-9]+\.[0-9]+)|([+-]?[5-9]+)","1.") # false correct
re.search("([+-]?[0-9]+\.[0-9]+)|([+-]?[5-9]+)","1") # false correct
# expecting right side expression of pipe-sign is running
re.search("([+-]?[0-9]+\.[0-9]+)|([+-]?[5-9]+)","5") # true correct
re.search("([+-]?[0-9]+\.[0-9]+)|([+-]?[5-9]+)","5.") # true Wrong
re.search("([+-]?[0-9]+\.[0-9]+)|([+-]?[5-9]+)","5.") # true Wrong
有人能指出我做错了什么吗?谢谢
发布于 2020-01-23 18:09:53
发布于 2020-01-23 16:13:38
https://stackoverflow.com/questions/59882709
复制相似问题