Is there some regex that can be passed to re-seq such that it will behave like .split?
user=> (seq (.split "a,b,c,,e" ","))
("a" "b" "c" "" "e")
user=> (re-seq #"[^,]" "a,b,c,,e")
("a" "b" "c" "e")
user=>
As you can see the regex [^,] is not quite acceptable because it won't pick up on empty columns in a delimited file. Am I stuck with .split or can re-seq be made to work?
Try
(re-seq #"[^,]+|(?<=,)(?=,)" "a,b,c,,e")
I hope that Clojure regexes support lookbehind assertions.
Explanation:
[^,]+ # Either match one or more non-comma characters
| # or
(?<=,)(?=,) # match the empty string between two commas
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With