我有一个字符串,它看起来是这样的:用匹配组中的下划线替换空格字符?
"(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"
我想使用Python正则表达式后删除在列名中的空格“端)AS”字符。结果应该成为这样的事情
"(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"
我能够匹配那些我有兴趣在Python [example here]使用正则表达式的部分,但我想知道如何优雅地(例如,一个衬垫或在Python化方式)替换匹配的组中的空格字符。
请在下面检查我的答案。请注意,虽然基于lookbehind的正则表达式在这种情况下更为优化,但我决定尽可能少地改变原始模式本身,以显示如何在单个lambda替换中处理多个*组。 –