This is horrible, but it works for now until I work out how to do bash regexes better!