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