处理Unicode字符时,请使用Unicode字符串。在程序的输入/输出边界处转换Unicode字符串。如果可能,请切换到最新的Python 3。它可以更好地处理Unicode。
# -*- coding: utf-8 -*-
import re
import io
with io.open('input.txt', 'r', encoding='utf8') as input, \
io.open('output.txt', 'w', encoding='utf8') as output:
for line in input:
word = line.strip() # this will remove all leading/trailing whitespace.
# Rule 1: ^VCV -> V[=]CV
match = re.match(u'^[AEIOUYaeiouy]([bcÄdfghjklÅmnÅprsÅtwzżź]|rz|sz|cz|dz|dż|dź|ch)[aÄ
eÄioóuy].*(.*\[=\].*)*', word)
result = match.group() if match else None
if result == word:
word = re.sub(u'(?<=^[AEIOUYaeiouy])(?=([bcÄdfghjklÅmnÅprsÅtwzżź]|rz|sz|cz|dz|dż|dź|ch)[aÄ
eÄioóuy])', u'[=]', word)
outLine = word + u'\n'
output.write(outLine)