Skip to content

Instantly share code, notes, and snippets.

@TanmayChakrabarty
Last active September 20, 2021 20:47
Show Gist options
  • Save TanmayChakrabarty/b318b2ae49f57340d54f47a976bc4b96 to your computer and use it in GitHub Desktop.
Save TanmayChakrabarty/b318b2ae49f57340d54f47a976bc4b96 to your computer and use it in GitHub Desktop.
Get all matched items in an array
function regexMatchAll(regex, subject){
let matches = [...subject.matchAll(regex)];
let result = [];
for(let i=0;i<matches.length;i++){
result.push(matches[i][0]);
}
return result;
}
let testString = 'orders[0][column]';
console.log(regexMatchAll(/([^\[\]]+)/gm, testString));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment