Fixing regex var replacement issue