gpt4 book ai didi

postgresql - postgres regexp_replace 否定连续字符组的存在

转载 作者:行者123 更新时间:2023-11-29 13:28:53 25 4
gpt4 key购买 nike

我有一个数据库导出,其中包含一些错误的字符替换(如 è => e')。所以我必须在 postgres 中将其改回。
我要疯狂地制作一个能捕捉到这样的东西的多合一正则表达式:

cassine' de' pecche' e'

它必须成为

cassinè de' pecchè è

(de'不得改变)。

我设法通过两次通过:

UPDATE mytable SET comun1=UPDATE mytable SET comun1=regexp_replace(column1,'([^dnNn])(e\'')', '\1\2è', 'g');   

UPDATE mytable SET comun1=UPDATE mytable SET comun1=regexp_replace(column1,'([^\s])([dnNn])(e\'')', '\1\2è', 'g');

基本上我想从替换空格后跟 d 或 n 和后跟 e'(如“de'”)中排除,并在所有其他情况下更改 e'。
我尝试了 (?!\s[nNdD])(e\'') 但它仍然将“de'”更改为“dè”

有人对此有解决方案吗?

最佳答案

select regexp_replace($$cassine' de' pecche' e'$$, $$(\s[^dn]?|\w\w)e'$$, '\1è', 'gi')
regexp_replace
----------------------
cassinè de' pecchè è
(1 row)

解释:

(\s[^dn]?|\w\w)e'
^ ^ ^
| | followed by e'
| or 2 word chars
space optionally followed by d or n

关于postgresql - postgres regexp_replace 否定连续字符组的存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28459540/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com