Simplify conditional logic to a regex