-1

With PostgreSQL I want to remove the image classes. The image classes has different ones. This is what I want to achieve of some sort:

<img src="#" class="one two three" alt="">

So that the result is:

<img src="#" class="" alt="">

So I can then do a UPDATE:

UPDATE posts SET content = 'class="new-class"' WHERE content = 'class=""'

I don't think the above is a good way to do it though.

Urdro
  • 867
  • 2
  • 8
  • 11
  • While the question does not mention `regexp_replace()`, [this post](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454) is most relevant. DO READ TO THE VERY END! – Patrick Aug 23 '16 at 13:21

1 Answers1

1
update posts set content = replace(content, 'class="one two three"', 'class=""')
Ric.H
  • 489
  • 4
  • 12
  • Sorry. But the `class="one two three"` could be in a another order for example `class="two one three"` or `class="new one image"`. How could that be achieved? – Urdro Aug 23 '16 at 13:08
  • 1
    `update posts set content = replace(content, substring(content from '%#"class="%" #"%' for '#'), 'class="" ')` – Ric.H Aug 23 '16 at 13:45
  • 1
    @Ric.H, you should update your answer rather than post another comment ;) – tetri Feb 15 '17 at 10:26