Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression get last characters [duplicate]

Tags:

regex

I want to write a regular expression which will take the characters from the last "slash" "/" to the right.

Exemple1 : http:// thesite.com/tester/blabla/this_is_the.jpg - I want to extract only the "this_is_the.jpg" Exemple2 : http:// thesite.com/tester/blabla/this_is_2.jpg - Only the "this_is_2.jpg"


1 Answers

It's as simple as:

[^/]+$

Which basically says: "give me all characters at the end that are not slashes".

Example:

$ echo 'http:// thesite.com/tester/blabla/this_is_the.jpg' | egrep -o '[^/]+$'
this_is_the.jpg
like image 69
xaizek Avatar answered Mar 15 '26 07:03

xaizek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!