2

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/')

Nux Mr
  • 21
  • 3

1 Answers1

0

Use Regex in this case

UPDATE table_name SET column_name = REGEXP_REPLACE(column_name, 'website.com/download/(.*?)/', 'newUrl.com/download/');
Rhett Harrison
  • 430
  • 4
  • 19
  • Let me know if this doesn't work or doesn't answer the question. I haven't used MariaDB before but I am pretty familiar with SQL in general – Rhett Harrison Apr 20 '22 at 23:12
  • Thank you for answering. But i have many different url not only one. – Nux Mr Apr 20 '22 at 23:57
  • Does the URL you are setting it to change as well? Or will they all be https://newurl.com/download/filename.zip – Rhett Harrison Apr 21 '22 at 03:34
  • I suppose my question would be better asked. Are you changing the domain to something and keeping the filenames the same? Are you changing them both? It would be easier I think if you were changing the domain name and it was the same change every time. Filenames however obviously change for every file – Rhett Harrison Apr 21 '22 at 03:40
  • I have around 8000 URL with different name and different folder name : Example : https://website.com/download/8fd4g8er4ger5f84/namedifferent.zip https://website.com/download/fggf4hf5gh4/namedifferent.zip https://website.com/download/1v8t77hth/namedifferent.zip https://website.com/download/fgh48rt4g/namedifferent.zip only https://website.com/download/ is same I need to keep filename.zip and change the rest My problem is I don't know how to change these url with different folder name (8fd4g8er4ger5f84 / fggf4hf5gh4 / 1v8t77hth / fgh48rt4g / etc.) – Nux Mr Apr 21 '22 at 08:04
  • I know this is something like that : UPDATE `sql_table` SET `column_name` = REGEXP_REPLACE(column_name, 'website.com/download/8fd4g8er4ger5f84/', 'NEWwebsite.com/download/') But I don't know how to manage folder diferrent named like > 8fd4g8er4ger5f84 or dff8f4zef or fd8g41r8f4e or 4fd84dfg or fd8g78fdg or v4c587gz etc – Nux Mr Apr 21 '22 at 08:37
  • Is 'website.com/download/*/' syntax is good ? – Nux Mr Apr 21 '22 at 08:41
  • 1
    Found it : UPDATE table_name SET column_name = REGEXP_REPLACE(column_name, 'website.com/download/(.*?)/', 'NEWwebsite.com/download/') It is easy .. but i'm noob :D Hope this can help someone :) – Nux Mr Apr 21 '22 at 09:03
  • I hope you don't mind, but I am going to update my answer so that the community finds it more helpful @NuxMr – Rhett Harrison Apr 21 '22 at 21:48
  • 1
    alright thx for your help btw :) – Nux Mr Apr 23 '22 at 16:59