Reputation: 65
href="something.do?something_id=-1&something=u_container_id=6445194287^something=70a6c7ca4f9d52001cb17e918110c72f";
href1="something.do?something=u_container_id=7757033893";
var id = href1.substr(href1.lastIndexOf("=") + 1 , href1.length);
This work good for href1 but not for href. I need to make a code which will get only container_id value. It can be 10 digits or less or more but will be only numbers
Upvotes: 1
Views: 163
Reputation: 22885
You can use a regular expression to find all these container_id= parts. Then you can extract the digits for each match:
href.match(/container_id=\d+/g).forEach(function(item){
var id = item.split('=')[1];
console.log(id);
});
Upvotes: 0
Reputation: 115222
You can use match()
with capturing group regex
href = "something.do?something_id=-1&something=u_container_id=6445194287^something=70a6c7ca4f9d52001cb17e918110c72f";
href1 = "something.do?something=u_container_id=7757033893";
var id = href1.substr(href1.lastIndexOf("=") + 1, href1.length);
var id = href1.match(/container_id=(\d+)/)[1];
document.write(id);
Upvotes: 2