New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String.prototype.split() with a regex with grouping ( parentheses ). #3467

BobStein opened this Issue May 29, 2017 · 0 comments


None yet
2 participants

BobStein commented May 29, 2017

Splitting a string normally leaves out the delimiters.

> "a and b or c".split(/and|or/)
["a ", " b ", " c"]

But grouping-parentheses in a regular expression preserves them in the odd-numbered indexes of the output.

> "a and b or c".split(/(and|or)/)
["a ", "and", " b ", "or", " c"]

This was not supported in IE before version 11. And MDN says "not all browsers support this capability." I'd like to see whether other browsers support this feature. But the current information in does not address this.

These methods are supported in effectively all browsers (since IE6+, Firefox 2+, Chrome 1+ etc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment