There are multiple ways to extract a specific part of a string.
Method 1: Using indexOf and substring
var str = "www.medicoshere.com/register.html?23457cedlske234cd";
var partIndex = str.indexOf("?");
var part = str.substring(partIndex + 1); // 23457cedlske234cd
Method 2: Using Split
var part = str.split("?")[1];
An issue with using substring
is that if the specified part is not found in the string, the entire string will be returned instead.
var str = "www.medicoshere.com/register.html#23457cedlske234cd";
var partIndex = str.indexOf("?");
var part = str.substring(partIndex + 1); // www.medicoshere.com/register.html#23457cedlske234cd
On the other hand, using split would result in the value of part being undefined
.