Regex Full URL -> Base URL
Full url:
http://stackoverflow.com/questions/6038061/regular-expression-to-find-urls-within-a-string
Base:
stackoverflow.com
Regex:
(http(s)?:\/\/)|(\/.*){1}
Example in JavaScript:
function toBaseURL(fullURL){
return fullURL.replace(/(http(s)?:\/\/)|(\/.*){1}/g, '');
}Written by Agam
Related protips
1 Response
Thank you very much! It works
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Regex
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#