0
Bu işlevi, normal ifadeler kullanarak basitleştirmek istiyorum. örnek girilebilirBu işlev için normal ifade
text =' At&T, " < I am > , At&T so < < & & '
Kodum:
def replaceentity(text):
import re
import uuid
from cgi import escape
invalid_chars_map = {'&':'&', '<':'<', '>': '>', '"': """}
replace_values = {'<':'<', '>':'>'}
replaced_dict = {}
for key, value in replace_values.items():
text = text.replace(key, value)
print "after replace >>>>>> " + text
for word in text.split():
if word in invalid_chars_map.values():
print word
uid = str(uuid.uuid4())
text = text.replace(word, uid)
replaced_dict[uid] = word
text = escape(text)
for i in replaced_dict.keys():
text = text.replace(i, replaced_dict[i])
print text
hayır ... kodun mantığında gördüğünüz gibi, eğer değer sözlükte zaten mevcutsa, bu kelimeyi atlamak istiyorum, çünkü bu sözcüğü atlamak istiyorum. –