EveryGoodWork / ChapterVerse

Scripture lookup bot written in Rust.
GNU General Public License v3.0
4 stars 1 forks source link

Scripture Regex #18

Closed PeterMHammond closed 1 month ago

PeterMHammond commented 4 months ago

This is the RegEx for quickly finding potential scripture in a sentence. Note this currently has to be built for each book of the bible. An initial fast parse for the potential of a scripture entry. Then needs to be isolated to an actual scripture. This is a good starting place. (?<![1-3] )(?<![1-3])(\bjohn ?\d{1,3}:\d{1,3}(-\d{1,3})?\b|\bjhn ?\d{1,3}:\d{1,3}(-\d{1,3})?\b|\bjn ?\d{1,3}:\d{1,3}(-\d{1,3})?\b)

PeterMHammond commented 4 months ago

Example text to parse would be: My favorite scripture is 1 Tim 3:16-17 or My favorite scripture is 1 Timothy 3:16-17 or My favorite scripture is 1Tim3:16-17 More tests need to be added.

PeterMHammond commented 1 month ago

This was simplified down into 2 checks. The first determines if it's a possible scripture by simply checking for a ":" like gen 1:1. Every reference for scripture will have a ":" between the chapter and verse. Then when the possible scripture is extracted with this simplified regex it is immediately checked against the data, and returns the matching scripture or none showing that it's not a valid reference. regex: Regex::new(r"(?i)(\d?\s?[a-z]+\s?\d?)\s(\d+):(\d+)(?:-(\d+))?")