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:
Flowchart:
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.
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
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics