To remove last segment from URL with JavaScript, we can use the string's slice method. We call url. slice with the indexes of the start and end of the substring we want to return. The character at the end index itself is excluded.
To request removal of a directory or site, click on the site in question, then go to Site configuration > Crawler access > Remove URL . If you enter the root of your site as the URL you want to remove, you'll be asked to confirm that you want to remove the entire site.
To remove a hyperlink but keep the text, right-click the hyperlink and click Remove Hyperlink. To remove the hyperlink completely, select it and then press Delete.
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\.)/,"");
Yes, there is a RegExp but you don't need to use it or any "smart" function:
var url = "www.testwww.com";
var PREFIX = "www.";
if (url.startsWith(PREFIX)) {
// PREFIX is exactly at the beginning
url = url.slice(PREFIX.length);
}
If the string has always the same format, a simple substr()
should suffice.
var newString = originalStrint.substr(4)
Either manually, like
var str = "www.test.com",
rmv = "www.";
str = str.slice( str.indexOf( rmv ) + rmv.length );
or just use .replace()
:
str = str.replace( rmv, '' );
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