I am trying to extract a value from simplest JSON in javascript.
After searching i found match
to be closest solution.
But trying this with grouping of RegExp
, it does not give suitable result.
My object is {"a":"one"}
and regex i am building is new RegExp('{"a":"(.*)"}','g')
my results with
'{"a":"one"}'.match(new RegExp('{"a":"(.*)"}','g'))
is ["{"a":"one"}"]
'{"a":"one"}'.match(new RegExp('{"a":"(.*)"}'.replace(/([+?^=!:${}|\[\]\/\\])/g, "\\$1"),'g'))
is also ["{"a":"one"}"]
I am expecting the result should have been ["{"a":"one"}", "one"]
what wrong is happening here?