I'm porting a script from bash to the busybox shell, ash - how can I check what file extension a file has (and strip that extension to get a generate a directory name) ?

The bash code fragment looks like this:

> 
> 
> ```
> if [[ "$filename" =~ '\.tar\.gz' ]]; then
>     tar -xzf "$filename"
>     dirname="${filename::${#filename}-7}"
> elif  [[ "$filename" =~ '\.tar\.bz2' ]]; then
>     tar -xjf "$filename"
>     dirname="${filename::${#filename}-8}"
> elif  [[ "$filename" =~ '\.tar\.xz' ]]; then
>     xzcat "$filename" | tar -x
>     dirname="${filename::${#filename}-7}"
> else
>     echo "Unknown extension for file: ${filename}" >&2
>     exit 1
> 
> ```
> 
> 

On running the script it contains I get output showing that the code to check the extension is not recognised:

> 
> Unknown extension for file: zlib-1.2.11.tar.gz
> 
> 
>