Use regex to replace if/else blocks