[CLJS-1320] clojure.string/split adds separator matches & failed matches (nil) when the separator is a regex with alternation Created: 26/Jun/15 Updated: 10/Apr/17
I want to split a string on "; ", and optionally discard a final ";". So, I tried:
In Clojure, this does what I want:
In ClojureScript, I get:
I'm not sure to what extent this is a platform distinction and to what extent it's a bug. Returning nils and seperators from clojure.string/split's output seems like it's against string.split's contract?
|Comment by Erik Assum [ 10/Apr/17 11:12 AM ]|
Might not be the answer you want, but Clojurescript uses js' split implementation.
Which means that to avoid this, you should use non-capturing groups:
Which incidentally can be simplified to
Which produces the result you're after in both clojure and clojurescript.