javascript undefined elements occurs during regex split

The following code results in undefined element at the middle

"Hello World\n\nhello world".split(/\n(\n|\t|\s)*?\n/)
"Hello World\n\nhello world".split(/\n(\n|\t|\s)*\n/)

The output is

["Hello World", undefined, "hello world"]

I wanted to split if there were two new line characters with any number of new line or space or tab character between them as long as they are not alphabets or symbols or numbers.


Use a non-capturing group to prevent the contents of the capture group(s) from being included.


It will return:

"Hello World\n\nhello world".split(/\n(?:\n|\t|\s)*?\n/);
// ["Hello World", "hello world"]