如果我在 Postgresql 9.1 专栏中有这个:
foo foo <th id="ddd"> foo foo <th id="www"> foo
我希望它更新为:
foo foo <th> foo foo <th> foo
我尝试过 regex_replace,但我没有成功。
最佳答案
假设您有一个这样的表:
CREATE TABLE table1
(
a character varying NOT NULL,
...
)
您可以使用以下 regexp_replace:
update table1 set a = regexp_replace(a, '(.*?)<(\w+)\s+.*?>(.*)', '\1<\2>\3', 'g');
'g'
标志表示替换所有匹配的模式,而不仅仅是第一个。
有了这个输入:
foo foo <th id="ddd"> foo foo <th id="www"> foo<div id="hey">
我得到以下输出:
foo foo <th> foo foo <th> foo<div>
关于html - Postgresql——清理字符串中间的 HTML 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12235517/