bash - string manipulation get string before or after substring

You have to place the asterisk to the other end of the string. The asterisk stays for "whatever", so

${string%$searchstring*}

means "remove from string everyting from the searchstring onwards".

This is documented in man bash under "Parameter Expansion".