Home > Software design >  I want print the words written in the camel case by python
I want print the words written in the camel case by python

Time:03-21

I want Extract and print all the words in a given string written in the camel case (if each word in the middle begins with a capital letter, with no spacing in between) the code have use Regular Expression by python for ex: input: "I write a syntax of RegularExpression", output:"RegularExpression"

Thanks for help..

CodePudding user response:

You're probably looking for something like ([A-Z]\w ) This will match any uppercase word with 0 or more single uppercase letters within.

Use a website like regex101.com to adapt/build your own regex expression. It's a handy thing to know

CodePudding user response:

If you want a regex that matches a word that contains an uppercase character you could use:

\S [A-Z]\S 
  • \S matches any non-whitespace character
  • matches at least one of the previous capture group
  • [A-Z] matches any character between A and Z (all uppercase characters)

So this regex matches non-whitespace characters that contain an uppercase character. Note that this will match:

  • regEx
  • RegEx
  • REGEX

It will not match:

  • regE
  • Regex
  • reg Ex
  • Related