Clojure Cookbook: Regular Expressions

Parsing CSV Files

Problem

How do I parse the lines of a comma-separated value file?

http://tools.ietf.org/html/rfc4180

(defn parse-line [s]
(map (fn [[a b c]] (or b c)) (re-seq #"(?:([^\",]+)|\"((?:[^\"]|\\\")*)\")" s)))

Back to Clojure Cookbook: Table of Contents


Comments

Add a New Comment
or Sign in as Wikidot user
(will not be published)
- +

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License