是否有一些可以传递给re-seq的正则表达式,使其表现得像.split
?
user=> (seq (.split "a,b,c,,e" ","))
("a" "b" "c" "" "e")
user=> (re-seq #"[^,]" "a,b,c,,e")
("a" "b" "c" "e")
user=>
正如您所看到的,正则表达式[^,]
不可接受,因为它不会在分隔文件中的空列上获取。我是坚持使用.split
还是re-seq
可以工作?
答案 0 :(得分:6)
尝试
(re-seq #"[^,]+|(?<=,)(?=,)" "a,b,c,,e")
我希望Clojure正则表达式能够支持lookbehind断言。
<强>解释强>
[^,]+ # Either match one or more non-comma characters
| # or
(?<=,)(?=,) # match the empty string between two commas