#!/bin/sh # w=blah.txt; # w=blah_txtx; w=blah_txt; # This was a problem ext="bla .bla txt .txt \.txt .bmp"; echo; echo "----- filter user string \$ext ----"; echo "\$ext= $ext"; ext=${ext//\\} # removes all escape characters ext=${ext//./\\.} # replaces all . with \. echo "\$ext= $ext"; echo; echo "----- test strings: -----"; echo; echo " \$w test line: $w"; echo "\$ext test list: $ext"; echo; echo "---- 1 ---------------------"; for ea in $ext; do echo -n "try [[ $w =~ $ea ]] : "; if [[ $w =~ $ea ]]; then echo "YES "; else echo "NO "; fi; done; echo; echo "---- 2 ---------------------"; for ea in $ext; do echo -n "try [[ $w =~ $ea$ ]] : "; if [[ $w =~ $ea$ ]]; then echo "YES"; else echo "NO "; fi; done;