0

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?

1
  • MySQL doesn't support back-references in regexp_replace(). Commented Jul 11, 2022 at 19:52

1 Answer 1

1

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.