Thursday, February 12, 2015

IE8 can’t handle split by regex

FYI, this is a very strange bug I just stumbled upon in IE8, even other IE versions running in IE8 mode (which means – anyone using IE with SharePoint 2010)…

It appears while IE8 can handle a simple string split by character, such as “a,b,c,d”.split(“,”) – it is having a really hard time working with a regular expression split.

It is supposed to be supported, it is working on any other browser including IE9+…

Here is what I have, splitting a string by matching tokens inside [ ]:

var arr = str.split(/\[(.*?)\]/);

All browsers will return all text before, inside and after the matches.

IE8, it appears, is the only one out of the bunch not returning the text inside the token.

BTW, if you ask me – IE8 is the only browser who is actually doing what I asked – which is to split by the match, while I would say all other browsers are in the wrong – splitting by the matches themselves in the regex… but if all browsers do one thing and IE8 does another, it just makes it impossible to rely and use this API.

Well, off to find another solution.

No comments: