我需要将每个“්”和上一个字符替换为下一段。如何使用Python 3做到这一点?
paalau jaiwaiThenayaiya makana්nata dawasaka ් oba mata hamauwauwaa Andaurau maawathe atha්waela ් baendagarena apa daredarenaa paiyamna ් karerauwaa kaisaidaa nomaekarena mathake raendailaa oba maa haeradaa warena්wauwaa obatama urauma magema saihainaya obage ahase laiyawewaa
答案 0 :(得分:0)
您正在寻找re.sub()
:
import re
result = re.sub(".?්", "[REPLACE WITH]", "paalau jaiwaiThe thanaiya makana්nata dawasaka් oba mata hamauwauwaa andaurau maawaThe atha්waela් baendagarena apa daredarenaa paiyamna් karerauwaa kaisaidaa nomaekarena mathake raendailaa oba maa haeradaa warena්wauwaa obatama urauma magema saihainaya obage ahase laiyawewaa")
print(result)
්
匹配的regex,如果有(.
),则它前面的任何单个字符(?
)都可以。