I have a string like
This {manish } {abc} {123 } is my string CopyResult={ Region : us-west-2, AmiId : ami-0f60f66f},{ Region : us-west-1, AmiId : ami-2884de48}, manish kumar
I want to get the sub-string like
{ Region : us-west-2, AmiId : ami-0f60f66f},{ Region : us-west-1, AmiId : ami-2884de48}
After getting that I want to convert that string to JSON.
I am trying code like
var pt = /CopyResult=.*/;
var copyAmisResult = copyAmilog.match(pt);
console.log("copyAmilog -- " + copyAmisResult);
Output
CopyResult={ Region : us-west-2, AmiId : ami-0f60f66f},{ Region : us-west-1, AmiId : ami-2884de48},
Could some one please suggest me the modified regular expression so that I can get my output.
PS:- I need to remove CopyResult= from begning of the string and , from last of the string and also it can have multiple {}. After that is there an easier way to convert that string to JSON object. Could JSON.parse() be useful?
JSON.parse('[' + '{"one": 1}, {"two": 2}, {"three": 3}' + ']');just noticed that your variable names and values aren't wrapped in quotes, need to do that too..