I've googled and gone through stack overflow Q&A's but haven't found this exact scenario. I have an object like so:
props: {
"label": "1rem",
"text3": "1rem",
"text2Button": "1rem",
"1": "1rem",
"5spacing": 2
}
I am using this regex pattern to capture the object property names and remove the double quotes based on a simplified version of another answer:
/"([^"]+)":/g
This worked great, but I wanted the numbers to keep their double quotes, so I changed it to this:
/"([^"0-9]+)":/g
However, this only matches "label"
and any property with a number is excluded. I understand why this is happening, what I can't figure out is how do I match properties that have a number in them but exclude those that begin with a number.
The desired regex pattern would match "label"
, "text3"
, and "text2Button"
only so that I could then transform the object to this:
props: {
label: "1rem",
text3: "1rem",
text2Button: "1rem",
"1": "1rem",
"5spacing": 2
}
(I couldn't figure out how to do combine the exclude ^
with the start of string ^
. Nor could I figure out the proper place to add the |
operator, or if that was even the correct approach.)