Lucas Amorim Silva
Lucas Amorim Silva

Reputation: 605

Regex - Take all caracters after the last slash

I have this:
http://server/service/local/repositories/domain/content/name/1.0.0-SNAPSHOT/name2-1.0.0-20161114.174435-142.pom

I would like to take only name2-1.0.0-20161114.174435-142.pom using Regex

I tried something like \/(.)*.pom$ but it selects all caracters starting with the two slashs.

Heeeelp!

Upvotes: 0

Views: 65

Answers (4)

Kirill Polishchuk
Kirill Polishchuk

Reputation: 56162

You can use this regex: [^\/]+$

https://regex101.com/r/Zn5n6e/1

Upvotes: 2

Wagner DosAnjos
Wagner DosAnjos

Reputation: 6374

Try the following expression:

[^\/]+\.pom$

Regex101 demo: https://regex101.com/r/dOg0yi/1

Upvotes: 3

Ibrahim
Ibrahim

Reputation: 6088

You can try to use Lookaround:

(?=name\w)\V+

Demo: https://regex101.com/r/u1o3yG/2

Upvotes: 2

Dmitry Zayats
Dmitry Zayats

Reputation: 473

echo "http://server/service/local/repositories/domain/content/name/1.0.0-SNAPSHOT/name2-1.0.0-20161114.174435-142.pom"|sed 's/^.*\/\([^/]*\)$/\1/'

Upvotes: 2

Related Questions