从电子邮件字符串中删除特殊符号
Remove special symbols from email string
我需要替换电子邮件字符串中的一些字符,正是这样的操作:
lower_email = str.lower(str.split(email,'@')[0])
nopunc_email = re.sub('[!@#$%^&*()-=+.,]', ' ', lower_email)
nonum_email = re.sub(r'[0-9]+', '', nopunc_email).strip()
但是在SQL
我尝试使用表达式 TRANSLATE(lower(email), 'a1_a.a-a@1-+()a ', 'a a a a')
,但它没有给我解决方案。
提前致谢!
例如:
import re
email = 'some_email.example-2021@gmail.com'
lower_email = str.lower(str.split(email,'@')[0])
nopunc_email = re.sub('[!@_#$%^&*()-=+.,]', ' ', lower_email)
nonum_email = re.sub(r'[0-9]+', '', nopunc_email).strip()
result 'some email example'
SELECT email,
TRIM(
TRANSLATE(
LOWER(SUBSTR(email, 1, INSTR(email, '@') - 1)),
'!_#$%^&*()-=+.,0123456789',
' '
)
) AS translated
FROM table_name
其中,对于示例数据:
CREATE TABLE table_name (email) AS
SELECT 'some_email.example-2021@gmail.com' FROM DUAL;
输出:
EMAIL
TRANSLATED
some_email.example-2021@gmail.com
some email example
db<>fiddle here
我需要替换电子邮件字符串中的一些字符,正是这样的操作:
lower_email = str.lower(str.split(email,'@')[0])
nopunc_email = re.sub('[!@#$%^&*()-=+.,]', ' ', lower_email)
nonum_email = re.sub(r'[0-9]+', '', nopunc_email).strip()
但是在SQL
我尝试使用表达式 TRANSLATE(lower(email), 'a1_a.a-a@1-+()a ', 'a a a a')
,但它没有给我解决方案。
提前致谢!
例如:
import re
email = 'some_email.example-2021@gmail.com'
lower_email = str.lower(str.split(email,'@')[0])
nopunc_email = re.sub('[!@_#$%^&*()-=+.,]', ' ', lower_email)
nonum_email = re.sub(r'[0-9]+', '', nopunc_email).strip()
result 'some email example'
SELECT email,
TRIM(
TRANSLATE(
LOWER(SUBSTR(email, 1, INSTR(email, '@') - 1)),
'!_#$%^&*()-=+.,0123456789',
' '
)
) AS translated
FROM table_name
其中,对于示例数据:
CREATE TABLE table_name (email) AS
SELECT 'some_email.example-2021@gmail.com' FROM DUAL;
输出:
TRANSLATED some_email.example-2021@gmail.com some email example
db<>fiddle here