I used the following question, Remove "www", "http://" from string, to remove the HTTP
and HTTPS
from my url. Now I want to remove the path on the end of the url as well and can't seem to get the pattern. This is the code I am trying to use:
str = str.sub(/^https?\:\/\//, '').sub(/^www./,'').sub(/^\/*/,'')
The first two .sub
work as expected and remove the HTTP
, HTTPS
and www.
from the url but the path i.e. http://URL/path/to/remove/
stays with the URL. As can be seen above I have tried the following pattern /^\/*/
in the third sub but it doesn't remove the path on the end of the url. What pattern will remove all characters after the base URL?