Quantcast
Channel: How to get string between the last two "/" symbols - Super User
Viewing all articles
Browse latest Browse all 5

Answer by Cyrus for How to get string between the last two "/" symbols

$
0
0

With bash and a regex:

s="/dir0/dir1/dir2/filename.ext"
[[ $s =~ ([^/]*)/[^/]*$ ]] && echo "${BASH_REMATCH[1]}"

Output:

dir2

Viewing all articles
Browse latest Browse all 5

Trending Articles