Reputation: 923
I'm trying to get rid of the protocol and domain from a URL in jQuery with .replace()
and regex, but it leaves the string exactly the same no matter what.
var selectedDocumentUrl = "http://mysite.test.com/files/somefile.pdf";
var assetUrl = selectedDocumentUrl.replace('/http://[^\/]+/g', '');
Here is a jsfiddle of the code
Upvotes: 0
Views: 54
Reputation: 388316
You have to pass a regular expression to replace() not a string literal
var assetUrl = selectedDocumentUrl.replace(/http:\/\/[^\/]+/g, '');
Demo: Fiddle
Upvotes: 4