Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace upper case with lower case using regex?

Tags:

c#

regex

I need to replace upper case letter in variable name with lower case letter and add space

For example:

NotImplementedException should be Not implemented exception UnhandledException should be Unhandled exception

like image 374
aron Avatar asked Jul 13 '10 08:07

aron


People also ask

How do you match upper and lower cases in regex?

Using character sets For example, the regular expression "[ A-Za-z] " specifies to match any single uppercase or lowercase letter. In the character set, a hyphen indicates a range of characters, for example [A-Z] will match any one capital letter.

How do I convert upper case to lower case?

To use a keyboard shortcut to change between lowercase, UPPERCASE, and Capitalize Each Word, select the text and press SHIFT + F3 until the case you want is applied.

How do you capitalize in regex?

matches any character. \U converts to uppercase.

Can regex replace characters?

RegEx makes replace ing strings in JavaScript more effective, powerful, and fun. You're not only restricted to exact characters but patterns and multiple replacements at once.


1 Answers

Since you did not specify a language, I'll give an example in C#. I am sure your language will offer something like it.

String s = "NotImplementedException"; s = Regex.Replace(s, @"\B[A-Z]", m => " " + m.ToString().ToLower()); // s = "Not implemented exception" 
like image 188
Jens Avatar answered Sep 23 '22 12:09

Jens