I'm trying to convert PascalCase property names such as Is24Hour
, Is512
to JSON-style lowercase with underscores (ie. is_24_hour
, is_512
) using C#.
So far I've got far but it doesn't work for multiple numbers.
([A-Z])([A-Z0-9][a-z])|([a-z0-9])([A-Z0-9])
With the replacement expression ($1$3_$2$4
)
For example "Is24Hour"
becomes "Is_24_Hour"
(which is then lower-cased by .ToLower()
).
but "Is512"
becomes "Is_51_2"
.