Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
什么Python正则表达式可以验证这种类型的字符串_Python_Regex_Python 2.7 - Fatal编程技术网

什么Python正则表达式可以验证这种类型的字符串

什么Python正则表达式可以验证这种类型的字符串,python,regex,python-2.7,Python,Regex,Python 2.7,在Python中验证这种类型的输入字符串时遇到问题 工作日的字符数可变 Regular: 16Mar2009(mon), 17Mar2009(tues), 18Mar2009(wed) Regular: 20Mar2009(fri), 21Mar2009(sat), 22Mar2009(sun) Rewards: 26Mar2009(thur), 27Mar2009(fri), 28Mar2009(sat) 我想验证整行,每行都应具有以下特定格式: <name>: <date

在Python中验证这种类型的输入字符串时遇到问题

工作日的字符数可变

Regular: 16Mar2009(mon), 17Mar2009(tues), 18Mar2009(wed)
Regular: 20Mar2009(fri), 21Mar2009(sat), 22Mar2009(sun)
Rewards: 26Mar2009(thur), 27Mar2009(fri), 28Mar2009(sat)
我想验证整行,每行都应具有以下特定格式:

<name>: <date>(<weekday>), <date>(<weekday>), <date>(<weekday>)
:(),(),()
提前谢谢

试试这个:

if re.search(r"[\d]{1,2}[a-z]{3}[\d]{4}\([a-z]{3,4}\)", string, re.IGNORECASE):
    # Successful match
else:
    # Match attempt failed

你需要更具体一点。您想验证什么?每条线?每个日期段?只是工作日的名字?整个事情作为一个整体?等等。现在澄清问题,再看看问题。对不起,不是我投了反对票,但我测试了这个正则表达式,结果并没有达到预期效果。示例2009年3月20日(星期五)2009年3月21日(星期六)2009年3月22日(星期日)由于缺少“:”和“,”而匹配且不应匹配