Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upper and Lower camel case

I am trying to come up with a regex for both Upper and lower Camel case.

Here is what I tried

(([A-Z][a-z0-9]*){2,}|([a-z][A-Z0-9]*){2,})

Trying to match Upper camel case with this - ([A-Z][a-z0-9]){2,} but it is matching other combinations as well. Similar is the case with the second part - ([a-z][A-Z0-9]){2,})

like image 884
Ankit Avatar asked Sep 26 '13 07:09

Ankit


Video Answer


1 Answers

This would match upper and lower camel case phrases containing at least one upper case in the word.

Upper Camel Case

[A-Z][a-z0-9]*[A-Z0-9][a-z0-9]+[A-Za-z0-9]*

example:HelloWorld, AQuickBrownFox

Lower Camel Case

[a-z]+[A-Z0-9][a-z0-9]+[A-Za-z0-9]*

example: helloWorld, aQuickBrownFox

like image 123
JackDev Avatar answered Sep 22 '22 14:09

JackDev