I have the following regex code that i'm trying to perfect for scripture searches. ... are 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 into the issue is that is with multiple passage references like
Genesis 3:2 1 Chronicles 2:2 if I use a regex with also a space in search the function assumes that 1 in Chronicles is Genesis 1 and does not recognize it and send it to preg_replace_callback
. Any suggestions?
The input is a string
that is whole paragraph like
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 to do is make it so that it would match the scripture and passage and then turn it into an a href
link using pre_replace_callback
function.
In your case, you can use the regex provided by @danielson317 in the comments and extend it to suit your needs. It will even handle "Genesis 3:2 1 Chronicles 2:2" correctly, giving you
<a href...>Genesis 3:2</a> <a href...>1 Chronicles 2:2</a>
.You can even make it a class: