如果所有数据都与您的示例一致,那么这应该有效:
编辑:更新以匹配整行。这将排除无效列表中的任何子字符串匹配。但是,它假定 OP 不想匹配任何子字符串。
^[a-z0-9]+_[0-9\/]+_[A-Z0-9:\s]+$
例如,在 python 中:
>>> import re
>>> s = 'b_06/18/2012_06:02:34 PM'
>>> pattern = '^[a-z0-9]+_[0-9\/]+_[A-Z0-9:\s]+$'
>>> m = re.match(pattern, s)
>>> m.group(0)
'b_06/18/2012_06:02:34 PM' # <======== matches from valid list
>>> s = 'CCC Valuation_CCC Valuation_b_06/28/2012_05:57:20 PM'
>>> m = re.match(pattern, s)
>>> m.group(0)
Traceback (most recent call last): # <======= does NOT match from invalid list
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'