user10791031
user10791031

Reputation:

Select everything before a colon en put it between quotes

I have a big array and I need to get everything before the colon between quotes

I've tried this regex but it didn't work for me.

^([/.+?(?=:)]+)$

this is my array now:

A0 05 15 : "rgb(60, 50, 51)",
A0 05 25 : "rgb(82, 69, 71)",
S 2030-B : "rgb(120, 172, 191)",
S 2030-B10 : "rgb(119, 175, 187)"

What I want it do be:

"A0 05 15" : "rgb(60, 50, 51)",
"A0 05 25" : "rgb(82, 69, 71)",
"S 2030-B" : "rgb(120, 172, 191)",
"S 2030-B10" : "rgb(119, 175, 187)"

Upvotes: 0

Views: 67

Answers (1)

Emma
Emma

Reputation: 27723

Here, we might want to have two capturing groups, one for keys and one for values, similar to:

(.+)(?:\s+):(?:\s+)(".+",?)

then make a replacement with:

"$1":$2

DEMO

RegEx Circuit

jex.im visualizes regular expressions:

enter image description here

Upvotes: 1

Related Questions