Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get the headers from markdown along with the header type
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
You can’t perform that action at this time.