I don't think regular expressions can solve it.
import re
text = "fd-sf+1%2'fd4't&y'y67"
text2 = ''
pattern='[\W]'
for i in range(len(text)):
if re.match("'",text[i]):
text2 = text2 + text[i]
continue
text2 = text2 + re.sub(pattern, ' ', text[i])
>>> text2
"fd sf 1 2'fd4't y'y67"
© 2024 OneMinuteCode. All rights reserved.