How to replace the characters !@#$%^*_+\= in a string using RegEx with Python

1 Answer

0 votes
import re

input_text = "The!quick@brown#fox$jumps%^over*_the+\\lazy=dog."
pattern = r"[!@#$%^*_+=\\]"  
replacement = " "

# Perform regex replacement
result = re.sub(pattern, replacement, input_text)

print("Original:", input_text)
print("Modified:", result)

 
 
'''
run:
 
Original: The!quick@brown#fox$jumps%^over*_the+\lazy=dog.
Modified: The quick brown fox jumps  over  the  lazy dog.
 
'''

 



answered Jun 11 by avibootz
...