Simplify regex and conditional