我正在使用Python中的regex库。我正在创建一个条件,我想绕过样本字符串,因为我逐行读取文件。
如果找到类似的格式,我想绕过字符串:
03/27/2016 07:58:17.442
要绕过的示例字符串:
03/27/2016 07:58:17.442 U:Event: Current Process Recipe Name = PFCA-800Pulse.prc [LLA_01] [2016-03-27_003_A1B]
我目前的代码:
self.matchObj = re.match( r'([0-9])\w+', l)
if not self.matchObj:
#do the following code here
答案 0 :(得分:0)
试试这个:
self.matchObj = re.match( r'^[0-9/]{10}.+$', l)
https://regex101.com/r/kAsQUn/1
编辑根据评论:
self.matchObj = re.match( r'\d\d/\d\d/\d\d\d\d \d\d:\d\d:\d\d\.\d\d\d', l)