Issue
I've tested this regex and it finds the /
character without issues.
Then why is this statement not replacing that character?
import re
str = 'bla / bla / bla'
str = re.sub(r'/\//g', ' - ', str)
Solution
You must not have tested your regex against Python's engine, for which your syntax is off. The re.sub
function does not use delimiters. Use this version:
str = 'bla / bla / bla'
str = re.sub(r'\s+/\s+', ' - ', str)
print(str) # bla - bla - bla
Answered By - Tim Biegeleisen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.