#!/usr/bin/env clj (ns split-sample (:use [clojure.contrib.str-utils :only (re-split)] [clojure.contrib.seq-utils :only (flatten)] clojure.contrib.pprint)) (def string "a=1,b=5,c=8,d=89, a=5,b=65,c=8,d=19, a=41,b=98,c=8,d=34, a=341,b=125,c=3,d=19, a=65,b=23,c=8,d=70") (println (str "string:\n" string)) (def outbuff (java.io.StringWriter.)) (binding [*out* outbuff] (pprint (for [chunk (partition 4 (partition 2 (re-split #"=|,\s*" string)))] (apply hash-map (flatten chunk))))) (println (str "munged:\n" outbuff)) (System/exit 0) ; string: ; a=1,b=5,c=8,d=89, a=5,b=65,c=8,d=19, a=41,b=98,c=8,d=34, a=341,b=125,c=3,d=19, a=65,b=23,c=8,d=70 ; munged: ; ({"a" "1", "b" "5", "c" "8", "d" "89"} ; {"a" "5", "b" "65", "c" "8", "d" "19"} ; {"a" "41", "b" "98", "c" "8", "d" "34"} ; {"a" "341", "b" "125", "c" "3", "d" "19"} ; {"a" "65", "b" "23", "c" "8", "d" "70"})