从 Python 输入中删除从右到左的标记和其他 unicode 字符 [英] Removing right-to-left mark and other unicode characters from input in Python
本文介绍了从 Python 输入中删除从右到左的标记和其他 unicode 字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用 Python 编写一个论坛.我想删除包含从右到左标记之类的输入.建议?可能是正则表达式?
I am writing a forum in Python. I want to strip input containing the right-to-left mark and things like that. Suggestions? Possibly a regular expression?
推荐答案
如果您只是想将字符限制为特定字符集的字符,您可以使用该字符集对字符串进行编码并忽略编码错误:
If you simply want to restrict the characters to those of a certain character set, you could encode the string in that character set and just ignore encoding errors:
><预><代码>>>>uc = u'aäöüb'>>>uc.encode('ascii', '忽略')'ab'
这篇关于从 Python 输入中删除从右到左的标记和其他 unicode 字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文