python - How to remove space after slash "/" -
i working python , want remove blank spaces in urls, in order restore broken links.
this typical case have deal with.
text https:// sr.a i/gmf
the link has 1 blank space after slash (/) can expected. can have other blank spaces randomly distributed.
first, want fix if present space after slash (/)
.replace('/ ', '//')
this code works fine replace blank space after slash, there way fix link if blank space occurs anywhere else without removing white spaces since need preserve meaning of text?
use regexp lib https://docs.python.org/3.6/library/re.html following regexp
import re text = re.sub(r"[/]\s", "/", text) # r"" --> regexp in python # [/] --> slash # \s --> blank
in online regexp editor can play around make regexp more stable corner cases
Comments
Post a Comment