UseChange #!/bin/sh to #!/bin/bash, and use double brackets instead:
if [[ $1 =~ $re ]]; then
This is the extended test command, as opposed to the (regular) test command. =~ can only be used with the [[ ... ]] version, and requires Bash 3.0 or later.