Move assignment into condition
Use non-exact matches rather than regex

Using interpolation in a regex doesn't escape the string being
interpolated. This could cause some unexpected results. Use a non-exact
match instead.