Home > Net >  Update with regexp_replace replaces match with literal regex pattern
Update with regexp_replace replaces match with literal regex pattern

Time:07-12

I am trying to update a column in MariaDB using regexp_replace. I've tested this out in this fiddle and it works just fine, however when I update and export the table, it seems that the match is replaced by the literal regex pattern - href="#h_$1" .

This is my query:

UPDATE blog_posts
SET blog_content = regexp_replace(blog_content, 'href="[^#"] #h_(. )"', 'href="#h_$1"');

Did anyone encounter this before and if yes how can I solve it?

CodePudding user response:

You can use \\1 to select the pattern. try:

UPDATE blog_posts
SET blog_content = regexp_replace(blog_content, 'href="[^#"] #h_(. )"', 'href="#h_\\1"');

see manual: https://mariadb.com/kb/en/regexp_replace/

  • Related