Regex, replace all underscore and special char with spaces?

python, regex

Solution

Underscore is considered a "word character" in PCRE regular expressions. If what you want to match is "anything that is not a word character or an underscore", try this:

new_str = re.sub(r'[\W_]', ' ', new_str)

Problem

so im trying to replace all special chars into spaces, using regex: my code works, but it wont replace underscore, what should i do? code: ``` new_str = re.sub(r'[^\w]', ' ', new_str) ``` its working on all of the other special chars but not underscore.

Original source