Postgresql -- Cleanup Html Tags In Middle Of String
If I have this in a Postgresql 9.1 column: foo foo  foo foo   foo  And I want it to update to this: foo foo   foo foo   foo 
 
Solution 1:
Assuming you have a table like this:
CREATETABLE table1
(
  a charactervaryingNOTNULL,
  ...
)
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>
Post a Comment for "Postgresql -- Cleanup Html Tags In Middle Of String"