The split functionality seems to be different between Java and JavaScript.
I do not exactly need to match a certain regular expression criteria, or use lookahead based regex. My problem resides with empty matches being trailed after final matching of the split regex ( which is a simple set of character and not an expression ).
Below is an example of the output I am trying to achieve and what am I really getting.
Java
("~#~~#~~#~A~#~B~#~C~#~D~#~E~#~~#~~#~").split("~#~")
/* results with an array of length 8 */ (java.lang.String[]) [, , , A, B, C, D, E]
Javascript
"~#~~#~~#~A~#~B~#~C~#~D~#~E~#~~#~~#~".split("~#~")
/* results with an array of length 11 */ ["", "", "", "A", "B", "C", "D", "E", "", "", ""]
I really can't put my hands on a good explanation for this as I am working with a Java application and the split is causing me trouble, I want the same result as in JavaScript. How can I get that?
split
in C works differently as well (by complaining about not being able to find it, mostly).Trailing empty strings are therefore not included in the resulting array.
split
with-1
as the second. See Amadan's answer.