w3resource

Python: Split a string at uppercase letters


43. Split into Uppercase Letters

Write a Python program to split a string into uppercase letters.

Sample Solution:

Python Code:

import re
text = "PythonTutorialAndExercises"
print(re.findall('[A-Z][^A-Z]*', text))

Sample Output:

['Python', 'Tutorial', 'And', 'Exercises']

Pictorial Presentation:

Python: Regular Expression - Split a string at uppercase letters.

Flowchart:

Flowchart: Regular Expression - Split a string at uppercase letters.

For more Practice: Solve these Related Problems:

  • Write a Python program to split a camelCase string into its constituent uppercase letters.
  • Write a Python script to divide a string at every uppercase letter and output the resulting list.
  • Write a Python program to separate a mixed-case string into segments starting at each uppercase letter.
  • Write a Python function to split a sentence into words based on uppercase letter boundaries.

Go to:


Previous: Write a Python program to find urls in a string.
Next: Write a Python program to do a case-insensitive string replacement.

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.