从Django的字符串中删除特殊字符 [英] Remove special chracters from a string in django
本文介绍了从Django的字符串中删除特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从电子邮件中删除所有特殊字符,例如"@",.".并将其替换为下划线"在python' unidecode '中有一些针对它的功能,但是并不能完全满足我的要求.谁能建议我一些方式,以便我可以在字符串中找到上述字符并将其替换为下划线".
I want to remove all special characters from email such as '@', '.' and replace them with 'underscore' there are some functions for it in python 'unidecode' but it does not full fill my requirement . can anyone suggest me some way so that I can find the above mention characters in a string and replace them with 'underscore'.
谢谢.
推荐答案
为什么不使用 .replace()
?
例如
a='testemail@email.com'
a.replace('@','_')
'testemail_email.com'
要编辑多个内容,您可能可以执行以下操作
and to edit multiple you can probably do something like this
a='testemail@email.com'
replace=['@','.']
for i in replace:
a=a.replace(i,'_')
这篇关于从Django的字符串中删除特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文