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

Popular posts from this blog

service - Android MediaPlayer calls onCompletion before it already finished -

javascript - Training Neural Network to play flappy bird with genetic algorithm - Why can't it learn? -

javascript - Create a stacked percentage column -