删除特殊标点

问题描述

在我的文字中,我有一些特殊字符,例如破折号和guillemet(尖引号),这些特殊字符不能通过省略string.punctuation删除

在Python 3中从字符串中删除这种标点符号的正确方法是什么?

import string

mystring = ' »De fleste – digitale –'
mystring.translate(str.maketrans('','',string.punctuation))
' »De fleste – digitale –'

解决方法

尝试一下:

import itertools as it

mystring = ' »De fleste – digitale –'
newstring = ''
mystring = newstring.join(it.filterfalse(lambda x: x in '»–',mystring))
print(mystring) #=> " De fleste  digitale"
,

这是一个简单的解决方案:

/vendor/laravel/framework/src/Illuminate/Auth/Passwords/PasswordBroker.php

您可以将要忽略的内容添加到/** * Create a new token record. * * @param \Illuminate\Contracts\Auth\CanResetPassword $user * @return string */ public function create(CanResetPasswordContract $user) { $email = $user->getEmailForPasswordReset(); $this->deleteExisting($user); // We will create a new,random token for the user so that we can e-mail them // a safe link to the password reset form. Then we will insert a record in // the database so that we can verify the token within the actual reset. $token = $this->createNewToken(); $this->getTable()->insert($this->getPayload($email,$token)); return $token; } 函数内的列表中