I want to remove the "
www." part from the beginning of an URL string
For instance in these test cases:
testwww.com (if it doesn't exist)
Do I need to use Regexp or is there a smart function?
This question is related to
Depends on what you need, you have a couple of choices, you can do:
// this will replace the first occurrence of "www." and return "testwww.com" "www.testwww.com".replace("www.", ""); // this will slice the first four characters and return "testwww.com" "www.testwww.com".slice(4); // this will replace the www. only if it is at the beginning "www.testwww.com".replace(/^(www\.)/,"");