UNPKG

verse-reference-regex

Version:

A regular expression that matches Bible verse references and ranges

21 lines (17 loc) 603 B
const { combine, flags, either, optional, } = require('regex-fun') module.exports = function createChapterVerseRangeRegex({ requireVerse = false, flags: regexFlags = 'i', } = {}) { const number = /(\d+)/ const numberAndOptionalLetter = /(\d+)([a-z])?/ const colonVerse = combine(':', numberAndOptionalLetter) const chapterAndVerse = combine(number, requireVerse ? colonVerse : optional(colonVerse)) const secondHalfOfRange = combine('-', either(/([a-z])/, /(\d+)([a-z])/, chapterAndVerse, numberAndOptionalLetter)) return flags(regexFlags, chapterAndVerse, optional(secondHalfOfRange)) }