I am trying to get a string to have an underscore ‘_’ everywhere on a case changes in a string to make it more clear to the user. For example if we have a String ‘personal IDnumber’, I want to make it to ‘personal_ID_number’. This is in C#.
Thank you, I appreciate any help, suggestions.
-Sid
Replace on a case change
You are looking for this (I removed the space before ID, assuming it a typo)
It will transform
personalIDnumberintopersonal_ID_numberSee it here on Regexr
the Lookbehind (
(?<=[a-z])) and lookahead ((?=[A-Z])) construction is matching the empty string between a lower case and a uppercase letter (or the other way round in the second part after the pipe|) and replace this with a underscore.Replace on a case change with optional whitespace
If you want to include whitespace in the replace, just include it between the lookarounds
It will transform
personal IDnumberintopersonal_ID_numberSee this here on Regexr
Replace on a case change, but each word starts with an uppercase
If you say every word starts with an uppercase letter, then you can do this
This will make from
this
See this here on Regexr