A quick simple regex question
I have a domain name in a string that I need to strip - There is always http://www.
and the domain always ends in "/
"
g_adv_fullpath_old = g_adv_fullpath_old.replace(/http\:\/\/www\.(.*?)\//ig, '');
how do I create the regex to strip the domain name?
Any help would be appreciated
I would simply split on "/". For example:
>>> "http://www.asdf.com/a/b/c".split("/").slice(3).join("/")
'a/b/c'
Why complications? Simple indexOf
will do.
First remove http://www
(10 characters), then everything before the first slash.
var s = "http://www.google.com/test";
s = s.substr(10);
s = s.substr(s.indexOf('/'));
alert(s);
Or split
, as David suggests.
An example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With