I have a set of URLs. Some of them have a string www as substring and some of them haven't. I need to remove prefixes in each URL.
I tried remove this prefixes using many variants of regexp:
newStr = str.replaceAll("http://|http://www.", "");
newStr = str.replaceAll("^http://|http://www.$", "");
newStr = str.replaceAll("http://|http://www.", "");
where str - is an inputted URL string, and newStr is the URL after replacement.
Each of these variants replaces only http:// prefix, but www. remains in result. How I can change my regexp to remove http:// string as well as http://www. string?
I know that I can use replaceAll() twice:
newStr = str.replaceAll("http://", "").replaceAll("www.", "");
But what should I do to remain one replaceAll() and edit only the regular expression?