andre
andre

Reputation: 7249

mySQL: Removing a regex substring

I have urls stored in my database table in the following format

http://domain.com/images/4/8/48bafb746bb7baa695481574afc345eb61af8d0a.jpg, and http://domain.com/images/0/f/0f602869e208139d2da67867359fb7cf092eb02b.jpg.jpg

I want to change the directory the file are stored in and reflect this change in the DB. Something like the following.

http://domain.com/images/48bafb746bb7baa695481574afc345eb61af8d0a.jpg, and http://domain.com/images/0f602869e208139d2da67867359fb7cf092eb02b.jpg.jpg

I simply want to move all images up two directories. How can I remove the top two directories from the string?

Upvotes: 0

Views: 85

Answers (1)

neiha
neiha

Reputation: 171

try with substring_index

 select concat('http://domain.com/images/', substring_index('http://domain.com/images/4/8/48bafb746bb7baa695481574afc345eb61af8d0a.jpg','/',-1))

to edit your records you could do something like this:

 update yourtable set yourcoulmnpath= concat('http://domain.com/images/', substring_index(yourcoulmnpath,'/',-1))

Upvotes: 3

Related Questions