I'm working on a project in clojure, which can interop with any java classes, so the answer to my question could be for either java or clojure.
Basically I need to be able to split a string into components based on a given delimiter (which will be more then one character) but at the same time keep the delimiters.
For example:
splitting "test:test:test" on ":" => [ "test" ":" "test" ":" "test" ]
splitting "::test::test::" on "::" => [ "::" "test" "::" "test" "::" ]
The closets I've come use using clojure's clojure.string/split
, but it doesn't actually return the delimiters. The second closest was using StringTokenizer, which does return the delimiters but doesn't accept multi-character delimiters.
Does anyone know of any solutions other then just breaking the string into a sequence of characters and running a weird reduce on it?