Is it possible to make a JavaScript error regex reject null?
Can String.split () method reject null values?
console.log("abcccab".split("c")); //result: ["ab", "", "", "ab"] //desired result: ["ab", "ab"]
-
While I tested this, I came across a partial answer to the case:
console.log("abccacaab".split(/c+/)); //returns: ["ab", "a", "aab"]
But the problem occurs when the match is at the beginning:
console.log("abccacaab".split(/a+/)); //returns: ["", "bcc", "c", "b"] // ^^
Is there a clean answer? Or do we just need to deal with this?
javascript null split regex
Isaac May 22 '13 at 20:47 2013-05-22 20:47
source share