w3resource

Python: Remove lowercase substrings from a given string

Python Regular Expression: Exercise-53 with Solution

Write a Python program to remove lowercase substrings from a given string.

Sample Solution:

Python Code:

import re
str1 = 'KDeoALOklOOHserfLoAJSIskdsf'
print("Original string:")
print(str1)
print("After removing lowercase letters, above string becomes:")
remove_lower = lambda text: re.sub('[a-z]', '', text)
result =  remove_lower(str1)
print(result)

Sample Output:

Original string:
KDeoALOklOOHserfLoAJSIskdsf
After removing lowercase letters, above string becomes:
KDALOOOHLAJSI

Flowchart:

Flowchart: Regular Expression -  Remove lowercase substrings from a given string.

Python Code Editor:

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

Previous: Write a Python program to insert spaces between words starting with capital letters.
Next: Write a Python program to concatenate the consecutive numbers in a given string.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://198.211.115.131/python-exercises/re/python-re-exercise-53.php