Skip to main content
Solved

Rename attribute from Proper Case to Underscore

  • August 12, 2020
  • 5 replies
  • 77 views

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

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

jdh
Contributor
Forum|alt.badge.img+38
  • 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+45
  • 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+38
  • Contributor
  • 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

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

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+45
  • Influencer
  • August 13, 2020

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