J. Scott Elblein
J. Scott Elblein

Reputation: 4283

MySQL: Mass Replace using a regex?

I'm trying to replace all instances of   with a simple space EXCEPT if it's surrounded by DIV tags. I've tried tinkering with the NOT REGEXP and NOT RLIKE within the replace query, like this:

UPDATE table SET column = replace(column,NOT REGEXP '>&#160;<',' ');

But it gives a syntax error. Anyone have any suggestions?

Upvotes: 0

Views: 1562

Answers (2)

Diego
Diego

Reputation: 18369

How about three separate updates...

  1. UPDATE table SET column = replace(column, '>&#160;<', '%%LOL$$');
  2. UPDATE table SET column = replace(column, '&#160;', ' ');
  3. UPDATE table SET column = replace(column, '%%LOL$$', '>&#160;<');

Upvotes: 1

Bruno Silva
Bruno Silva

Reputation: 3097

Something like this should work:

UPDATE table SET column = REPLACE(column, '&#160;', ' ') WHERE column NOT LIKE '%div>&#160;</%'

Upvotes: 0

Related Questions