From what I've tested
"aba".split(/a/).length
returns
I was always prepared to handle differences in DOM manipulation, or Events model, but I've thought that things like strings, regexps, etc. are well defined. Was I wrong?
IE removes from the split
result array all undefined or empty strings.
As your question seems to be about the existence of a standard, then EcmaScript is the best match in the Javascript world.
And the behavior of split on regex is documented : http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.4.14
As it obvious from the example, empty strings should not be removed from the resulting array, so IE (as suspected) is faulty.
"A<B>bold</B>and<CODE>coded</CODE>".split(/<(\/)?([^<>]+)>/)
evaluates to the array
["A", undefined, "B", "bold", "/", "B", "and", undefined, "CODE", "coded", "/", "CODE", ""]
In fact, there are other differences between browsers. A solution could be to use a cross-browser split regex script but it's probably better to be simply aware of the differences and handle with proper tests the array returned by split
. Or use some tricks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With