我有以下字符串
layout: default title: Envy Labs
What i am trying to do is create map from it
layout->default title->"envy labs"
Is this possible to do using sequence functions or do i have to loop through each line?
Trying to get a regex to work with and failing using.
(apply hash-map (re-split #": " meta-info))
最佳答案
user> (let [x "layout: default\ntitle: Envy Labs"]
(reduce (fn [h [_ k v]] (assoc h k v))
{}
(re-seq #"([^:]+): (.+)(\n|$)" x)))
{"title" "Envy Labs", "layout" "default"}
关于regex - Clojure 解析字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1447271/