Postgresql - 清理字符串中间的HTML标签 [英] Postgresql -- cleanup HTML tags in middle of string
本文介绍了Postgresql - 清理字符串中间的HTML标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在Postgresql 9.1列中有这个:
foo foo< th id =ddd> foo foo< th id =www> foo
我希望它能更新到这里:
foo foo foo foo< th> foo
我试过regex_replace,但是我没有成功。
CREATE TABLE table1
(
a字符变化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>
If I have this in a Postgresql 9.1 column:
foo foo <th id="ddd"> foo foo <th id="www"> foo
And I want it to update to this:
foo foo <th> foo foo <th> foo
I've tried regex_replace, but I have not succeeded.
解决方案 Assuming you have a table like this:
CREATE TABLE table1
(
a character varying NOT NULL,
...
)
You can use the following regexp_replace:
update table1 set a = regexp_replace(a, '(.*?)<(\w+)\s+.*?>(.*)', '\1<\2>\3', 'g');
The 'g'
flag indicates to replace all matching patterns, not only the first one.
With this input:
foo foo <th id="ddd"> foo foo <th id="www"> foo<div id="hey">
I get the following ouput:
foo foo <th> foo foo <th> foo<div>
这篇关于Postgresql - 清理字符串中间的HTML标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文
登录
关闭
扫码关注1秒登录
发送“验证码”获取
|
15天全站免登陆