View Full Version : split() with regexp in FF2 returns an array including delimiters?

06-06-2007, 06:43 AM
var myString = "hello0x0there";
splitString = string.split(/(0x0){1}/);

in firefox the returned array is 3 elements long, with the middle one being the actual 0x0.

is this the intended implementation, and why?


06-06-2007, 09:01 AM
the ()s in the regexp mean it will 'capture', to exclude the delimiter, you would want to use:

splitString = string.split(/(?:0x0){1}/);

The ?: makes the bracketed group 'non-capturing'. In the example you've given, then grouping with {1} isn't needed though, so you could just use

splitString = string.split(/0x0/);

or do away with RE all together, and use:

splitString = string.split('0x0');