我有一個單一參數的函數,它是一個包含重音字符的unicode字符串。我想在該字符串中找到一個或多個模式並將其打印出來。Python 2.7正確的語法重新匹配Unicode字符串中的重音字符?
我不知道如何正確地格式化模式,或者正確使用re.match與unicode,或者使用unicode提取match.groups()。使用ASCII更容易。哎呀。
的Python 2.7
sentence = "These characters, ÄÜ, are special."
def findInSentence(sentence):
pattern = re.compile("ÄÜ", re.UNICODE)
return re.match(sentence, pattern).groups()
這是行不通的。我無法編碼字符串或使用重新。功能不會出錯。 – 2014-09-28 09:10:23
@ user1473511:交換模式和字符串,請參閱我的編輯。 – Toto 2014-09-28 09:16:31
sentence =「這些字符,」很特別。「 該行引發錯誤。 – 2014-09-28 09:22:53