Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Match last word after /

Tags:

regex

so, i have some kind of intern urls: for example "/img/pic/Image1.jpg" or "/pic/Image1.jpg" or just "Image1.jpg", and i need to match this "Image1.jpg" in other words i want to match last character sequence after / or if there are no / than just character sequence. Thank you in advance!

like image 384
Le_Coeur Avatar asked Feb 16 '10 12:02

Le_Coeur


1 Answers

.*/(.*) won't work if there are no /s.

([^/]*)$ should work whether there are or aren't.

like image 50
dubiousjim Avatar answered Dec 18 '22 00:12

dubiousjim