w3resource

Python: Remove the parenthesis area in a string

Python Regular Expression: Exercise-50 with Solution

Write a Python program to remove the parenthesis area in a string.

Sample Solution:-

Python Code:

import re
items = ["example (.com)", "w3resource", "github (.com)", "stackoverflow (.com)"]
for item in items:
    print(re.sub(r" ?\([^)]+\)", "", item))
	

Sample Output:

example                                                                                                       
w3resource                                                                                                    
github                                                                                                        
stackoverflow 

Pictorial Presentation:

Python: Remove the parenthesis area in a string.

Flowchart:

Flowchart: Regular Expression - Remove the parenthesis area in a string.

Python Code Editor:

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

Previous: Write a Python program to remove words from a string of length between 1 and a given number.
Next: Write a Python program to insert spaces between words starting with capital letters.

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-50.php