w3resource

Python: Split a string at uppercase letters

Python Regular Expression: Exercise-43 with Solution

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.

Python Code Editor:

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

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

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.