How to find and delete all vowels from a string using regex? FOR EXAMPLE: INPUT= "Stackoverflow is Amazing" OUTPUT="Stckvrflw s mzng"
I am not able to find how to do this problem, Please help
CodePudding user response:
Here is your solution:
import re
def removeVowels(inp_str):
return re.sub(r'[aeiouAEIOU]', '', inp_str)
inp_str = "Stackoverflow is Amazing"
print(removeVowels(inp_str))
CodePudding user response:
This is a brute-force approach:
In [1]: input_str = "Stackoverflow is Amazing"
In [2]: vowels = ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U')
In [4]: output_str = ''.join([s for s in input_str if s not in vowels])
In [5]: output_str
Out[5]: 'Stckvrflw s mzng'