-2

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 :)

  • 1
    Does this answer your question? [Consecutive Pattern replacing is not happening with REGEXP\_REPLACE](https://stackoverflow.com/questions/50701025/consecutive-pattern-replacing-is-not-happening-with-regexp-replace) – Andreas is moving to Codidact Apr 14 '23 at 12:41

1 Answers1

1

You may try the following update query:

UPDATE yourTable
SET message = REGEXP_REPLACE(message, '''.*?''', '%PARAM%')
WHERE message LIKE '%''%''%';
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360