I want to write a template tag to replace spaces,tabs,new lines,commas,underscores with dashes to make a SEO friendly URL:
re.sub('\s+', '-', str)
this line of code replace spaces with dash and:
re.sub('(?<=[,.?!\t\n ])+', '-', str)
this line of code should replace ?<=[,.?!، and space with dash, but it doesn’t.
Have you considered using the built in
slugifyfilter?The problem with your second expression is you are using a positive lookbehind (
?<=).From regular-expressions.info:
The following is probably what you were trying to do:
This is replacing any sequence of characters
,.?!\t\nwith a single dash.