Regex 如何使用正则表达式替换postgresql中的字符串?
t、 emailAddresses包含逗号分隔的电子邮件地址 我想用“0”替换某些电子邮件地址,如何用正则表达式替换 我用replace()编写了它,但我想用regex wayemailAddresses编写它Regex 如何使用正则表达式替换postgresql中的字符串?,regex,string,postgresql,replace,pattern-matching,Regex,String,Postgresql,Replace,Pattern Matching,t、 emailAddresses包含逗号分隔的电子邮件地址 我想用“0”替换某些电子邮件地址,如何用正则表达式替换 我用replace()编写了它,但我想用regex wayemailAddresses编写它 SELECT t.emailAddresses, replace (replace (replace (replace (t.emailAddresses, 'jack@example.com', '0'), 'jack@mybox.com', '0'),
SELECT t.emailAddresses,
replace (replace (replace (replace (t.emailAddresses,
'jack@example.com', '0'), 'jack@mybox.com', '0'), 'emly@example.com',
'0'), 'emly@mybox.com', '0') as replaced_email_address
FROM table t
WHERE t.id = 100;
提前感谢 替换某物的一般正则表达式语法是:
SELECT REGEXP_REPLACE(mycolumn, $rxb$^jack@example\.com$$rxb$, $$0$$, 'g') FROM mytable;
但是
- 如果你要替换一个文字(某个不变的东西),那就没有意义了
- 如果您想替换以
jack开头的电子邮件,这一功能非常有用
SELECT REGEXP_REPLACE(mycolumn, $$^jack.*$$, $$0$$, 'g') FROM mytable;