import re text = "Hello, world! This is a \"small\" example. Can you handle it?" pattern = r'[,.!"\']' result = re.sub(pattern, ' ', text) print(result)