Skip to content

Instantly share code, notes, and snippets.

@trevsm
Created October 13, 2020 03:50
Show Gist options
  • Save trevsm/802ac37ee1d9592f15d1d7cb30c990b0 to your computer and use it in GitHub Desktop.
Save trevsm/802ac37ee1d9592f15d1d7cb30c990b0 to your computer and use it in GitHub Desktop.
// returns array with existing delimiters
function parseText(text){
const reg1 = /(?<=\[name\]|\[age\])/g // negative lookahead
const reg2 = /(?=\[name\]|\[age\])/g // positive lookahead
return(Array.prototype.concat.apply([], (text.split(reg1).map(m => m.split(reg2)))))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment