diff --git a/index.js b/index.js
index 973cf50..31079af 100644
--- a/index.js
+++ b/index.js
@@ -23,7 +23,8 @@ module.exports = function(input, options, cb) {
// Find the title of the page by identifying the
// The second match is the inner group
- var title = body.match('(.*)
')[1] || 'Page ' + (i + 1);
+ var foundHeadings = body.match('(.*)');
+ var title = foundHeadings && foundHeadings[1] || 'Page ' + (i + 1);
var anchor = title.toLowerCase().replace(/[^\w]+/g, '-');
return { title: title, anchor: anchor, body: body }