Created
February 21, 2018 16:54
-
-
Save captDaylight/bbc44c602de302b986de018b807a2219 to your computer and use it in GitHub Desktop.
Get the headers from markdown along with the header type
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
var re = /(#+)(.*)/; | |
var str = '## About Bottler\n\nThis is something about the project\n\n# something else\n'; | |
function findAll(regex, sourceString, aggregator = []) { | |
const arr = re.exec(sourceString); | |
if (arr === null) return aggregator; | |
const newString = sourceString.slice(arr.index + arr[0].length); | |
return findAll(regex, newString, aggregator.concat([arr])); | |
} | |
findAll(re, str); | |
// [ ["## About Bottler", "##", " About Bottler"], ["# something else", "#", " something else"] ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment