javascript - jquery / Get only number after particular word -


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 href1 not href. need make code container_id value. can 10 digits or less or more numbers

you can use match() 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);

regex explanation here

regular expression visualization


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -