Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Use Notepad++ to Capitalize Letters in Snake Case

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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')

>Solution :

In two steps (from the sample input):

'business_year'
'business_year_month'
'business_year_quarter'

First find ('|_)(\w) replace by $1\U$2\E:

'Business_Year'
'Business_Year_Month'
'Business_Year_Quarter'

Then find ^(.+)$ replace by ,dim_date[(\L$1\E)].alias\($1\):

,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')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading