Python Practice › RegEx Programs › Program 10
Remove special characters
Write a Python program to remove everything except letters, digits and spaces.
Output
Hello World 2026 SQAtools
Approach
[^A-Za-z0-9 ]matches unwanted characters.
Solution
import re print(re.sub(r"[^A-Za-z0-9 ]", "", "Hello, World! #2026 @SQA_tools"))Output
Hello World 2026 SQAtools
Learn the concept
New to this topic? Read the lesson, then come back.