Regex in ruby to enclose word before : with double quotes

北城以北 提交于 2019-12-11 21:01:55

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!