Regular expression with sed

Your main problem is that you're trying to use / as a separator, when / also is a character you'll be parsing.

You'll need to use a different separator, such as a pipe. Match everything and a /, then use \( and \) (capture groups) delimiting the part you want to extract, and use \1, rendering that group:

echo "yourstring" | sed 's|.*/\([^/]*\)$|\1|'

You may have it working without capture groups: just dropping everything until the last /:

echo "yourstring" | sed 's|.*/||'

Why not use basename for this? For example:

for file in *mp3; do basename "$file"; done

Tags:

Linux

Sed