我這種情況,我有錯點的句子來處理,這句話(。): sentence = 'Hi. Long time no see .how are you ?can you follow [email protected]?'
我試圖規範這句話,如果你看到它,有是一些錯誤的格式句子(.how,?can和。@ abcde)。我正在考慮使用正則表達式來處理這個問題,因爲句子不斷變化。這是到目前爲止我的代碼:(。
我寫了這個簡單的小程序: def main ():
with open("test.txt", "rt") as fin:
with open("out.txt", "wt") as fout:
for line in fin:
fout.write(line.replace("\", "/"))
print ("done")
的main() 我知道
我遇到了有關原始字符串的混淆和看似矛盾的規則。考慮下面的例子:
>>> text = 'm\n'
>>> match = re.search('m\n', text)
>>> print match.group()
m
>>> print text
m
這工作,這很好。
>>> text = 'm\n'
>>> match = re.search(r'm\n', tex