Skip to main content
Solved

Rename attribute from Proper Case to Underscore


Forum|alt.badge.img+3

Is there any way to rename attribute from  Proper Case to Underscore with BulkAttributeRenamer?

 

Here is a few examples 

OrgNameComment -> Org_Name_Comment

TaxRegNumber -> Tax_Reg_Number 

 

Ideas?

 

Thanks

Yarko

Best answer by ebygomm

You can access the matched string using \1 in the BulkAttributeRenamer, so if you match all words starting with a capital except the first one and then replace these with an underscore and themselves you should get what you are after

(?<!^)([A-Z]+[a-z]+)

 

Capture

 

 

If there are any numbers or other characters in your attribute names the regex will need amending

View original
Did this help you find an answer to your question?

5 replies

jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • August 12, 2020

I would have thought it would a simple regex replace in the bulkAttributeRenamer, but it doesn't seem to allow you to use regex in the replacement string.

 

Incidentally you may have better luck searching using the terms CamelCase and Snake_Case.


ebygomm
Influencer
Forum|alt.badge.img+32
  • Influencer
  • Best Answer
  • August 13, 2020

You can access the matched string using \1 in the BulkAttributeRenamer, so if you match all words starting with a capital except the first one and then replace these with an underscore and themselves you should get what you are after

(?<!^)([A-Z]+[a-z]+)

 

Capture

 

 

If there are any numbers or other characters in your attribute names the regex will need amending


jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • August 13, 2020
ebygomm wrote:

You can access the matched string using \1 in the BulkAttributeRenamer, so if you match all words starting with a capital except the first one and then replace these with an underscore and themselves you should get what you are after

(?<!^)([A-Z]+[a-z]+)

 

Capture

 

 

If there are any numbers or other characters in your attribute names the regex will need amending

Argh,  the replace slash is quirky, I was getting unhappy results with my original regex.

 

Yarko,

 

There are several variations in regex that will give you great results if all your attributes are straight camel case, but if you have any attributes that aren't, the behaviours change.

 

See for example \B([A-Z])   vs Elizabeth's regex  (?<!^)([A-Z]+[A-z]+)

RegEx


Forum|alt.badge.img+3
  • Author
  • August 13, 2020
ebygomm wrote:

You can access the matched string using \1 in the BulkAttributeRenamer, so if you match all words starting with a capital except the first one and then replace these with an underscore and themselves you should get what you are after

(?<!^)([A-Z]+[a-z]+)

 

Capture

 

 

If there are any numbers or other characters in your attribute names the regex will need amending

This works  beautifully ,

Thanks @ebygomm​  👍 

 


ebygomm
Influencer
Forum|alt.badge.img+32
  • Influencer
  • August 13, 2020
jdh wrote:

Argh, the replace slash is quirky, I was getting unhappy results with my original regex.

 

Yarko,

 

There are several variations in regex that will give you great results if all your attributes are straight camel case, but if you have any attributes that aren't, the behaviours change.

 

See for example \\B([A-Z]) vs Elizabeth's regex (?<!^)([A-Z]+[A-z]+)

RegEx

"Argh, the replace slash is quirky, I was getting unhappy results with my original regex."

 

I normally spend at least 5 minutes working out why \\1 isn't working in the string replacer before remembering i need brackets to get capturing groups


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings