Seeking help with grabbing key/value pairs from a string like {float: 'null', another: 'foo'}
. The desired output groups are float null
and another foo
.
My current regex pattern is
/\{(?<set>(?<key>\w*)\s*\:\s*(?<value>.*)?\s?)*\}/g
It correctly captures the keys, but struggles to extract individual values. I'm using named groups for clarity but need assistance in extracting each key/value pair when multiple pairs exist.
Appreciate any guidance.
Currently experimenting with
/\{(?<set>(?<key>\w*)\s*\:\s*(?<value>.*)?\s?)*\}/g
but the output shows:
the group 'set': float: 'null', another: 'foo'
(correct)
the group 'key': float
(correct)
the group 'value': 'null', another: 'foo'
(incorrect, seeking just null
)
Interested in capturing all key/value pairs if possible
Edit for more clarity:
My specific challenge involves parsing Markdown for use with custom components in Svelte, focusing on gathering props from markdown syntax on an image. According to my research on adding attributes to an image, it should resemble:
![Alt Text]https://<fullurl>.jpg "This is hover text"){prop1: 'foo', prop2: 'bar', float: true}
The reason for using regex is to parse the markdown string, not adhering strictly to JSON format ("
around the keys).