为什么我得到无效的结果?

时间:2018-08-16 08:13:58

标签: python

#input is of type U-1011-13-F-CS-498 where U 1011 AND F is fixed and all are varying
import re
def validateEnrollment(eno):
    match_obj=re.findall(r'("U")\-("1011")\-("[0-99]")\-("F")\-(["CS|EC|BT"])\-("[000-999]")',eno,re.I|re.M)
    if match_obj:
        print("Your eno is valid",match_obj)

    else:
        print("Invalid eno")

eno=input("enter your enrollment number")
print("the enrollment number is",validateEnrollment(eno))

1 个答案:

答案 0 :(得分:0)

您的必需表达式无效。尝试this

^U-1011-\d\d-F-(CS|EC|BT)-\d\d\d$

编辑:

在Python中,使用它来检查输入:

match = re.match(r'^U-1011-\d\d-F-(CS|EC|BT)-\d\d\d$', "U-1011-13-F-CS-498")
if match != None:
    return "Your eno is valid"