Using regex for custom pattern formatting

Got rid of that horrible case statement in favor of a regex.