Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次のような JSON 文字列があり{\"heading\":\"Test\",\"id\":1}、文字列から ID データを消去したいと考えています。
{\"heading\":\"Test\",\"id\":1}
試してみましtest.gsub(/\,\\"id\\"\:d+/, '')たが、うまくいきません。
test.gsub(/\,\\"id\\"\:d+/, '')
これを達成するにはどうすればよいですか?
Sergio の JSON.parse は考慮すべきものです。しかし、それをむき出しにすると、\あなたが見ている 's はおそらく実際には文字列の一部ではありません。それがirbの表示方法です。
\
だからtest.gsub(/,"id":\d+/, '')あなたが望むものでなければなりません。(正規表現の他のいくつかの小さなバグも修正されました)。
test.gsub(/,"id":\d+/, '')