php - Regex scripture match -


i have following regex code i'm trying perfect scripture searches. ... rest of 66 bible books.

/(?=\s)\b(genesis|exodus|leviticus|...)(\.)?(\s)?((\d{1,3})([:,-;]?(?=\d))?((\d{1,3})?([:,-;]?(?=\d))?){0,50})/iu 

where i'm running issue is multiple passage references genesis 3:2 1 chronicles 2:2 if use regex space in search function assumes 1 in chronicles genesis 1 , not recognize , send preg_replace_callback. suggestions?

the input string whole paragraph

mat 3:12; luke 3:17; revelation 16:14 • gathered, 7 mat 2:4; mat 22:34; mat 27:27; mar 4:1; mar 5:21; joh 11:47; act 4:26 • into, 1 revelation 13:10 • resorted, 1 joh 18:2 • themselves, 1 act 11:26 • together, 24 mat 13:2; mat 22:41; mat 26:3; mat 27:17; mat 27:62; mar 2:2; mar 6:30; mar 7:1; luke 22:66; joh 11:52; act 4:6; act 4:27; act 4:31; act 13:44; act 14:27; act 15:6; act 15:30; act 20:7; act 20:8; 1 corinthians 5:4; revelation 16:16; revelation 19:17; revelation 19:19; revelation 20:8 

what i'm trying make match scripture , passage , turn href link using pre_replace_callback function.

in case, can use regex provided @danielson317 in comments , extend suit needs. handle "genesis 3:2 1 chronicles 2:2" correctly, giving <a href...>genesis 3:2</a> <a href...>1 chronicles 2:2</a>.

you can make class:

<?php $scriptureutils = new scriptureutils(); echo $scriptureutils->addlinks($text);  class scriptureutils {      private $booksabbreviated = array(         "gen", "exo", "lev", "num", "deu", "jos", "jud", "rut", "1 sam", "2 sam", "1 kin",          "2 kin", "1 chr", "2 chr", "ezr", "neh", "est", "job", "psa", "pro", "ecc", "son",          "isa", "jer", "lam", "eze", "dan", "hos", "joe", "amo", "oba", "jon", "mic",          "nah", "hab", "zep", "hag", "zec", "mal", "mat", "mar", "luk", "joh", "act",          "rom", "1 cor", "2 cor", "gal", "eph", "phi", "col", "1 the", "2 the", "1 tim",          "2 tim", "tit", "phi", "heb", "jam", "1 pet", "2 pet", "1 joh", "2 joh", "3 joh",          "jud", "rev"     );      private $booksfullnames = array(         "genesis", "exodus", "leviticus", "numbers", "deuteronomy", "joshua", "judges",          "ruth", "1 samuel", "2 samuel", "1 kings", "2 kings", "1 chronicles",          "2 chronicles", "ezra", "nehemiah", "esther", "job", "psalms", "proverbs",          "ecclesiastes", "song of solomon", "isaiah", "jeremiah", "lamentations", "ezekiel",          "daniel", "hosea", "joel", "amos", "obadiah", "jonah", "micah", "nahum",          "habakkuk", "zephaniah", "haggai", "zechariah", "malachi", "matthew", "mark",          "luke", "john", "acts", "romans", "1 corinthians", "2 corinthians", "galatians",          "ephesians", "philippians", "colossians", "1 thessalonians", "2 thessalonians",          "1 timothy", "2 timothy", "titus", "philemon", "hebrews", "james", "1 peter",          "2 peter", "1 john", "2 john", "3 john", "jude", "revelation"     );      private $addlinkpattern;      public function __construct() {         $this->definelinkpattern();     }      public function addlinks($text) {         $returnstring = preg_replace_callback(             $this->addlinkpattern,             array($this, "addlinkcallback"),             $text         );         return $returnstring;     }      private function addlinkcallback($matches) {         $returnstring = "";         foreach($matches $match) {             $returnstring .= "<a href=\"bible.php?passage=$match\">$match</a>";         }         return $returnstring;     }      private function definelinkpattern() {         // important full names appear before abbreviated ones.         $booklist = implode("|", array_merge($this->booksfullnames, $this->booksabbreviated));         $this->addlinkpattern = "/\\b(?:$booklist)(?:\\s+\\d+)?(?::\\d+(?:–\\d+)?(?:,\\s*\\d+(?:–\\d+)?)*)?/";     }  } 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -