Replace URL with different string

367 Views Asked by At

I try to replace all my URL with another into my mariadb database (10.3.31)

URL's Example :

https://website.com/download/8fd4g8er4ger5f84/filename.zip
https://website.com/download/fggf4hf5gh4/filename.zip
https://website.com/download/1v8t77hth/filename.zip
https://website.com/download/fgh48rt4g/filename.zip

I want to replace : https://website.com/download/8fd4g8er4ger5f84 (< this using different hash folder name) with my new URL : https://newurl.com/download/filename.zip

I used "update / replace" SQL command in the past, but I don't know how to do with unique hash name folder like above

Help me please?


EDIT : Found it

Found it :

UPDATE table_name SET column_name = REGEXP_REPLACE(column_name, 'website.com/download/(.*?)/', 'NEWwebsite.com/download/')

1

There are 1 best solutions below

10
On

Use Regex in this case

UPDATE table_name SET column_name = REGEXP_REPLACE(column_name, 'website.com/download/(.*?)/', 'newUrl.com/download/');