I'm using Notepad++ to find/replace and can't quite get what I need.
My Current Output is being generated with ^(.+)$
as my Find and ,dim_date[(\1)].alias\((\1)\)
as my Replace. It's close, but I can't get the uppercase between the parenthesis as it is in the Desired Output.
If I can alter my find/replace to do it all in one step, that's cool; but I don't mind keeping my first find/replace and then performing another find/replace to get the snake case capitalized. Whatever is easier.
Sample Input:
'business_year'
'business_year_month'
'business_year_quarter'
My Current Output:
,dim_date['business_year'].alias('business_year')
,dim_date['business_year_month'].alias('business_year_month')
,dim_date['business_year_quarter'].alias('business_year_quarter')
Desired Output:
,dim_date['business_year'].alias('Business_Year')
,dim_date['business_year_month'].alias('Business_Year_Month')
,dim_date['business_year_quarter'].alias('Business_Year_Quarter')
h = ('a'..'z').zip('A'..'Z').to_h #=> {"a"=>"A", "b"=>"B", ... , "z"=>"Z"}
. E.g.,h['b'] #=> 'B'
. Then make use of the second form of the method String#gsub...str = 'business_year_quarter'
,",dim_date['#{str}'].alias('#{str.gsub(/(?<=_)[a-z]/, h)}'\)" #=> ",dim_date['business_year_quarter'].alias('business_Year_Quarter')"
.