Use REGEXP_REPLACE for replacing a string between quote

Advertisements

Use of REGEXP_REPLACE in MySQL/Maria DB for replacing "City ‘ABCDE’ not found" in "City %PARAM% not found"

Hi,

Someone can help me with the use of REGEXP_REPLACE in MySQL/Maria DB ?

I have a table with a column "message" with the value :

  • City ‘ABCDE’ not found
  • City ‘ABCDEFGH’ not found
  • City ‘AB’ not found
  • City ‘ABCDEFG HIJ KLM’ not found

I want to replace all string between ‘ by the string %PARAM% :

  • City %PARAM% not found
  • City %PARAM% not found
  • City %PARAM% not found
  • City %PARAM% not found

But I failed with the use of regex 🙁

Thank you in advance for your help 🙂

>Solution :

You may try the following update query:

UPDATE yourTable
SET message = REGEXP_REPLACE(message, '''.*?''', '%PARAM%')
WHERE message LIKE '%''%''%';

Leave a ReplyCancel reply