Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Use REGEXP_REPLACE for replacing a string between quote

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 ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 '%''%''%';
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading