I am trying to extract multiple parameter strings from the following kind of input:
var paramsString = "first='somevalue' second='another value' third='another'"
With the resulting object:
var paramsObject = {
first: 'somevalue',
second: 'another value',
third: 'another'
};
I initially thought I could do paramsString.split(" ") but then I realised (as illustrated above) that some of the values could have spaces in.
I then thought maybe a RegEx like:
paramsObject.first = paramsString.match("first='(.*)'")[0];
But that goes all the way to the last ' character after the third value.
I could do this with indexOf() and substring but that seems really verbose espsecially when scaling to more parameters.
What is the most efficent and neat way of doing this?