0
我需要找出一个给定的字符串是否是这种格式。正则表达式在python中为特殊字符
anystr3ing1 : somesrritn3g
下面是我的代码
prog = re.compile("([a-zA-Z0-9]\D)" + ":" + ([a-zA-Z0-9]\D)")
with open('data.txt','ru') as openfileobject:
for line in openfileobject:
if prog.match(line):
print line
但其没有给予任何输出
你的数据是什么? – LetzerWille
您有语法错误。这是你的实际代码中的情况吗?看第一行,在行尾附近缺少“+”和“([a-zA-Z0-9] \ D)”)'之间的“。 – idjaw
此外,这个网站将有助于快速测试正则表达式:http://pythex.org – idjaw