*NOTE* There is an updated version of this regex here
Sometimes it is convenient to convert a string that is in camel case (variable name, enum value, method name etc.) to a well formatted string that look nice to an average user.
The following Regex will find all capital letters that are surrounded by lower-case letters.
(?<=[a-z])(?<Letter>[A-Z])(?=[a-z])
Here is the complete program for testing.
class Program { static void Main(string[] args) { Console.WriteLine("Enter a camel case string"); string camelCaseString = Console.In.ReadLine() ?? string.Empty; var regex = new Regex("(?<=[a-z])(?<Letter>[A-Z])(?=[a-z])"); Console.WriteLine(regex.Replace(camelCaseString, " ${Letter}")); Console.ReadLine(); } }