0
給定的字符串正確的密鑰和值我有一個列表:如何解析爲使用Ruby
key1:this is an{example{of an example}I like} key2:this is another example key3: this is secondary{example{of an example}}
我需要單獨的鑰匙,通過差異比較鍵的值,所以結果我想獲得是:
{
:key1 => 'this is an [example[of an example]I like]',
:key2 => 'this is another example',
:key3 => 'this is secondary[example[of an example]]'
}
是這樣或類似的東西可能與Ruby或正則表達式?
你想返回什麼?哈希?一個字符串? – Mischa 2013-03-19 14:42:15
我希望它是散列。我目前試圖使用拆分和正則表達式除以「:」和「{}」,就我所知 – lifejuggler 2013-03-19 14:51:12
我編輯了你的問題,以便所需的返回值看起來像一個散列。目前還不清楚你的所有方括號是什麼意圖。隨時再次編輯,以明確。 – Mischa 2013-03-19 15:08:11