It will first finds that either two curly brackets opening at the same time then it will return an array contains all the possible matches .The g in it is the parameter of Regular Expression it will search globally.
In this case i have applied this function on my input box if its value changes, the function checks that if curly brackets occur then it will return an array.
If there will be one match found then it will return the value in array with an index but if there may be more than one match found it was returning an array with first match at index 0 and then two empty strings on index 1 and index 2 and then second match on index 3,it repeats this behavior after every match , So that's why i applied a loop with i+=3 at every iteration it will take a step of 2.
May be it was an expensive method but it solved my problem,As I have not worked much with Regular Expressions so that's why may be it was scrambled and time taken process but it worked for me.
Hope you find this article useful. Please share your thoughts or if there is any method by which this can be done easily in the comment section.