w3resource
Python Exercises

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 

Flowchart:

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

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

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?



New Content: Composer: Dependency manager for PHP, R Programming


bedava porno