I don't know the Python regular expression that removes special characters.

Asked 1 years ago, Updated 1 years ago, 64 views

If Python contains even one of the Windows file name unknown characters \:/ * ? " < > | I want to replace those characters with spaces.

I don't know how to write a regular expression to include everything.

Please answer

python regex

2022-09-22 16:50

1 Answers

You can just put in the characters you want to replace by |.

before_str = "a?a:aa<sdfsdf>"
after_str = re.sub("[?|<|>|?|:]", " ", before_str)
print(after_str)
a a aa sdfsdf


2022-09-22 16:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.