Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL String Last Index Of

I am able to use LOCATE to get the index of a character such as a . in www.google.com. Thus I can use substring to strip out everything before the first ..

Is there a way I can look for the last /?

So I can get test.htm out of http://www.example.com/dev/archive/examples/test.htm?

I do not want to say the 6th slash, I want to say the last slash. Can this be done?

like image 842
700 Software Avatar asked Sep 11 '25 09:09

700 Software


1 Answers

Use substring_index

select substring_index('http://www.example.com/dev/archive/examples/test.htm','/',-1)
like image 178
Nicola Cossu Avatar answered Sep 12 '25 22:09

Nicola Cossu