I have an POST AJAX command that returns the following:
`email{admin@stackoverflow.com} cid{215}`
What I want do is replace the email{} and the cid{} with using only the values as vars
var email = 'admin@stackoverflow.com'
var customer_id = 215;
They would appear like that. Is there a cleaner way than:
var result = "email{admin@stackoverflow.com} cid{215}";
// change to admin@stackoverflow.com cid{215}
var replace1 = result.replace("email{");
var replace1a = replace1.replace("}");
// change to admin@stackoverflow.com 215
var replace2 = result.replace("cid{");
var replace2a = replace1.replace("}");
// now we have an email, with a space and a number
// admin@stackoverflow.com 215 make before space string
// this would be email
// now make only the int a string called cid
First use a regular expression to extract desired data:
Now you can easily obtain values you want: