'Snake_Case to PascalCase with regex
I Have a C# project where the class properties are all in Snake_Case, I want to convert them to PascalCase as recommended by Capitalization Conventions
also, the parameter names are in snake_Case and I'm using angular on the frontend and during deserialization, these properties are converted to snake_Case I want to convert snake_Case to pascalCase
I'm using VS code so I wanna use the search and replace functionality
e.g
Snake_Case --> SnakeCase
snake_Case --> snakeCase
i have tried:
([a-z])_([A-Z])
$1$2
but that does not work on GG_Registration_Number is becomes GG_RegistraionNumber
Solution 1:[1]
G is in upper case, ([a-z]) only captures lower case.
Use
([a-zA-Z])_([A-Z])
EXPLANATION
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
[a-zA-Z] any character of: 'a' to 'z', 'A' to 'Z'
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
_ '_'
--------------------------------------------------------------------------------
( group and capture to \2:
--------------------------------------------------------------------------------
[A-Z] any character of: 'A' to 'Z'
--------------------------------------------------------------------------------
) end of \2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ryszard Czech |
