0

When I use a grouped expression in the regex in String.split, it results in keeping the separators in the result, without it the separators are lost. Is this an undocumented feature, or something I can rely on?

console.log('The quick brown fox jumped over the lazy dog.'.split(/h/g))
console.log('The quick brown fox jumped over the lazy dog.'.split(/(h)/g))
Martin Capodici
  • 1,486
  • 23
  • 27
  • [Not undocumented](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split#Splitting_with_a_RegExp_to_include_parts_of_the_separator_in_the_result) at all – CertainPerformance Dec 13 '18 at 01:04
  • Not sarcasm at all - "not undocumented" = "indeed documented". It's described in that section of the spec you link too as well, even with an example: `If the regular expression contains capturing parentheses, then each time separator is matched the results (including any undefined results) of the capturing parentheses are spliced into the output array.` – CertainPerformance Dec 13 '18 at 01:09
  • @CertainPerformance - apologies. I deleted that comment. – Martin Capodici Dec 13 '18 at 02:45

0 Answers0