3

是否有一些正则表达式可以传递给 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工作?

4

1 回答 1

6

尝试

(re-seq #"[^,]+|(?<=,)(?=,)" "a,b,c,,e")

我希望 Clojure 正则表达式支持后向断言。

解释:

[^,]+       # Either match one or more non-comma characters
|           # or
(?<=,)(?=,) # match the empty string between two commas
于 2012-06-20T17:31:07.927 回答