3

First question here. I'm trying to search and replace in MySQL to replace whole words only. Here's an example section of a string in the database:

...has a "front end" (not ending) that you are looking at now...

I want to be able to replace the word end while leaving the word ending alone.

This is my query so far, but it's not working. It's replacing both instances of end.

UPDATE mfvjy_content
SET introtext = REPLACE(introtext, 'end', 'endR')
WHERE introtext REGEXP '[[:<:]]end[[:>:]]' AND id = 2

Anyone got any ideas on why the word boundaries aren't working? Thanks!

Dharman
  • 30,962
  • 25
  • 85
  • 135
H Jones
  • 47
  • 4
  • 2
    the word boundaries are filtering the rows of your query (if there is end, it may be also ending). REPLACE replaces all substrings in those rows. see this http://stackoverflow.com/questions/986826/how-to-do-a-regular-expression-replace-in-mysql – 1010 Apr 10 '15 at 14:18
  • 1
    Ah that makes sense, no wonder it didn't work. I did the word replacement in PHP using preg_replace instead and just inserted the whole string back into the database. – H Jones Apr 10 '15 at 16:32

0 Answers0