Last active
September 20, 2021 20:47
-
-
Save TanmayChakrabarty/b318b2ae49f57340d54f47a976bc4b96 to your computer and use it in GitHub Desktop.
Get all matched items in an array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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