python - 从 Django 中的字符串中删除特殊字符

标签 python django

我想从电子邮件中删除所有特殊字符,例如“@”、“.”并将它们替换为“下划线” 在 python 'unidecode' 中有一些函数,但它不能完全满足我的要求。任何人都可以建议我一些方法,以便我可以在字符串中找到上面提到的字符并将它们替换为“下划线”。

谢谢。

最佳答案

为什么不使用 .replace()

例如。

a='testemail@email.com'
a.replace('@','_')
'testemail_email.com'

要编辑多个你可能会做这样的事情

a='testemail@email.com'
replace=['@','.']
for i in replace:
  a=a.replace(i,'_')

关于python - 从 Django 中的字符串中删除特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14747459/

相关文章:

python - 字典到字符串不作为字典读回

python - 构建 numpy 矩阵

python - Django Translation - 翻译动态字符串

html - Django - 在模板中转义引号

python - 将 mkv 文件转换为 mp4 给我 `filenotfounderror`

python - 来自不同应用程序的导入错误

python - Python 列表字典中的最小总和

python - 如何在开发中为 Django 提供 CSS?

python - Django- Graphite 烯 : how to filter with an OR operator

Django 不渲染 Glyphicons