I've searched extensively and reviewed various Q&A forums, but I haven't encountered a scenario quite like this. Here's an example of the object I'm working with:
props: {
"label": "1rem",
"text3": "1rem",
"text2Button": "1rem",
"1": "1rem",
"5spacing": 2
}
To extract the property names from this object and eliminate the double quotes, I utilized the following regex pattern, inspired by another answer:
/"([^"]+)":/g
Initially, this method worked well. However, I wanted to retain double quotes around numerical values. So, I modified the regex as follows:
/"([^"0-9]+)":/g
Unfortunately, this adjustment only captures properties without numbers. While I understand the reason behind this limitation, I'm struggling to find a solution that excludes properties starting with a number but includes those containing numbers within the name.
The desired regex pattern should identify "label"
, "text3"
, and "text2Button"
exclusively. With this capability, I could transform the object to reflect the following structure:
props: {
label: "1rem",
text3: "1rem",
text2Button: "1rem",
"1": "1rem",
"5spacing": 2
}
(I struggled to implement the exclude ^
with the start of string ^
, and determining the correct placement for the |
operator proved challenging. I question whether this was even the appropriate approach.)