Better way of handling regex