Delete all text up to a character in a URL- JavaScript?

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

Let’s say the following is our URL −";

We only need to get the last value and delete the rest i.e. the output should be −


For this, you can use replace() along with regular expression.


Following is the code −

var url = "";
var getValues=url.replace(/^.*\//, '');
console.log("The original value = "+url);
console.log("New Value = "+getValues);

To run the above program, you need to use the following command −

node fileName.js.

Here, my file name is demo258.js.


This will produce the following output on console −

PS C:\Users\Amit\javascript-code> node demo258.js
The original value =
New Value = index.asp
Updated on 09-Nov-2020 07:21:10