pstein Posted August 25, 2023 Share Posted August 25, 2023 Assume I want to delete a substring which starts with "#blah" until the end of string. #blah itself should be deleted too. How can I achieve this? e.g. var address = document.URL.replace("#blah",""); deletes only the keyword but not the following, remaining part. If "#blah" is not found in string then nothing should happen. Link to comment Share on other sites More sharing options...
Ingolme Posted August 25, 2023 Share Posted August 25, 2023 Find the position of the substring, then get everything up to that position. let pos = document.URL.indexOf("#blah"); let address = document.URL; if(pos >= 0) { address = address.substr(0, pos); } 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now