Reputation: 20001
I need to remove part of url if it matches //videoid?v=
assuming my url can be
- www.abc.com/video/
- www.abc.com/video/videoid?v=1234567
- www.abc.com/video//videoid?v=1234567
in case url has //
forward slash before videoid?v=
then i need to remove single /
from the url so that url will be correct such as www.abc.com/video//videoid?v=1234567
currentURL = document.URL;
Upvotes: 1
Views: 1583
Reputation: 6253
You can use regex and use it like this to remove double occurrences of "/":
"www.abc.com/video//videoid?v=1234567".replace(/([^:]\/)\/+/g, "$1");
Working example: https://jsfiddle.net/os5yypqm/3/
EDIT:
I edited the JSFiddle to include "http://" in front of the url so that you can see that this does not affect it (and also read it here). Can't use it on SO though so you need to see the fiddle.
Upvotes: 2
Reputation: 1
You can replace forward slash if followed by forward slash and "v"
with empty string
"www.abc.com/video//videoid?v=1234567".replace(/\/(?=\/v)/g, "")
Upvotes: 1
Reputation: 1930
If your only concern is the double slash.
var currentUrl = 'www.abc.com/video//videoid?v=1234567';
currentUrl.split('//').join('/');
Results in www.abc.com/video/videoid?v=12345678
Upvotes: 2