fork download
  1. import re
  2. s = "(case when Campaign='Back to School' and VariableName='Total_FB_Spend' then VariableValue else 0 end) AS Back to School_Total_FB_Spend,(case when Campaign='Back to School' and VariableName='Total_FB_Imp' then VariableValue else 0 end) AS Back to School_Total_FB_Imp"
  3. pat = r'(end\) as )([^,]*)'
  4. print(re.sub(pat, lambda m: "{}{}".format(m.group(1), m.group(2).replace(" ", "_")), s))
Success #stdin #stdout 0s 23304KB
stdin
Standard input is empty
stdout
(case when Campaign='Back to School' and VariableName='Total_FB_Spend' then VariableValue else 0 end) AS Back to School_Total_FB_Spend,(case when Campaign='Back to School' and VariableName='Total_FB_Imp' then VariableValue else 0 end) AS Back to School_Total_FB_Imp