簡體   English   中英

紅寶石的正則表達式在單詞之前用雙引號引起來

[英]Regex in ruby to enclose word before : with double quotes

我有一個要轉換為json字符串的字符串

以下是json的格式

               title: {
                    position: "bottom",
                    text: "Share of Internet Population Growth"
                },
                legend: {
                    visible: false
                },
                chartArea: {
                    background: ""
                },
                seriesDefaults: {
                    type: "donut",
                    startAngle: 150
                }

要將其轉換為JSON字符串,我需要將AnyKey:替換為"AnyKey":
我在讀有關gsub的文章。 什么是確切的正則表達式來替換這種字符串

提前致謝

(\w+)(?=:)

試試看。看演示。

http://regex101.com/r/zR2tR4/3

替換為"$1"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM