问题
I have a string which I want to convert in json string
Following is the format of the json
title: {
position: "bottom",
text: "Share of Internet Population Growth"
},
legend: {
visible: false
},
chartArea: {
background: ""
},
seriesDefaults: {
type: "donut",
startAngle: 150
}
To convert it toa JSON string i need to replace the AnyKey:
with "AnyKey":
I was reading about gsub. What can be exact regex to replace this kind of string
Thanks in advance
回答1:
(\w+)(?=:)
Try this.See demo.
http://regex101.com/r/zR2tR4/3
Replace by "$1"
.
来源:https://stackoverflow.com/questions/26013479/regex-in-ruby-to-enclose-word-before-with-double-quotes