Python Practice › RegEx Programs › Program 10

Remove special characters

EasyRegEx Programs · 10 of 20

Write a Python program to remove everything except letters, digits and spaces.

Advertisement
Output
Hello World 2026 SQAtools

Approach

  1. [^A-Za-z0-9 ] matches unwanted characters.

Solution

Python
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.

More regex programs

← All 20 RegEx Programs

Leave a Comment