How to use MariaDB REGEXP_REPLACE?

I have read the docs for MariaDB REGEX_REPLACE

but cannot get my query to work. I am storing links in a column link

and want to change the end of the link:

From www.example.com/<code>

to www.example.com/#/results/<code>

, where <code>

is some hexadical hash, for example. 55770abb384c06ee00e0c579

... I'm trying to:

SELECT REGEX_REPLACE("link", "www\\.example\\.com\\/(.*)", "www\\.example\\.com\\/#\\/results\\/\\1");

      

Result:

Showing rows 0 - 0

...

+3


source to share


1 answer


I was unable to figure out what was the first argument - the documentation says "subject". It turns out it's just the name of the column. So this works:



UPDATE my_table
SET my_link = REGEXP_REPLACE(
    my_link,
    "http:\\/\\/www\\.example\\.com\\/(.*)",
    "http:\\/\\/www\\.example\\.com\\/#\\/results\\/\\1")
WHERE my_link IS NOT NULL

      

+2


source







All Articles