I have a string like below…
var1=val1 var2=val2 var3="p1 p2 p3 p4" var4="p1 p2" var5=val5
Now how can I replace all the white spaces with underscore only inside "" using RegExp so that the string looks like below…
var1=val1 var2=val2 var3="p1_p2_p3_p4" var4="p1_p2" var5=val5
so that by using .replace('"','').split(' '), I can get an array like below…
Array(
var1: "val1",
var2: "val2",
var3: "p1_p2_p3_p4",
var4: "p1_p2",
var5: "val5"
)
no jQuery please…
I know this has been answered but I thought I’d share this regex using a positive look-ahead. This allows you to
replacewithout using a callback.To explain:
Then the
gwill repeat the search