Q:

capture the string next to known string using javascript/jQuery

I have a long string. How can I find a string next to the known string.
example: '.lot of text..."number":"999.999.9999","make_model":"device name"....lot of text.'.
I know this value "999.999.9999". Using this as a sub string how do I capture "device name" and pass it as an alert/console.log? The device name is not a constant length.
Thanks

A:

you can do something like this if you are sure the number is only repeated once and length is always the same and make_model is always next to it.
basically it finds index of number and adds the length of number plus make_model ("999.999.9999","make_model":") which is 29 characters. and then we get the rest of string after this until we reach a double quotation and thats the end of make_model and what you want.

var str = '.lot of text..."number":"999.999.9999","make_model":"device name"....lot of text.';
var chop = str.substr(str.indexOf('"999.999.9999"') + 29);
chop = chop.substring(0,chop.indexOf('"'));
console.log(chop);

