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.
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>