Does anyone know why "x" .split (/ (x) /). Does length return 0 in IE?

In IE, "x".split(/(x)/).length returns 0

In Firefox, Chrome, Safari and Opera 3 returned.

Does anyone know the reason? If possible, a link will be appreciated.

I believe this is an IE regex implementation problem, but I cannot find any document about this.

+6
javascript internet-explorer regex
source share
3 answers

You are right that there are problems with the implementation. IE ignores empty values ​​and blocks blocks in regular expressions.

So for

 "foo".split(/o/) 

IE gives

 [f] 

where other browsers give

 ["f","",""] 

and when adding capture:

 "foo".split(/(o)/) 

IE does the same, but the rest add the captured delimiter to the resulting array to give

 ["f","o","","o",""] 

So, unfortunately, you probably need to avoid using split or code to solve these problems.

+6
source share
+3
source share

I had the same issue with a broken IE split implementation.

Here is a small library file that fixed the problem perfectly.

+1
source share

All Articles