Any reason for not using literal regex from the beginning? Looks like unnecessary complexity. We also might want to use string in future to generate regex from pattern, which will break compatibility. So, my opinion that it is better to specify regex as param rather than using string to create regex.