This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
regular_expressions [2019/03/24 16:24] steve created |
regular_expressions [2019/03/24 16:26] steve |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Regular Expressions ====== | ====== Regular Expressions ====== | ||
- | Using regular expressions will help you do some advanced querying and data manipulation. I've mostly used them in PostgreSQL. | + | Using [[https://en.wikipedia.org/wiki/Regular_expression|regular expressions]] will help you do some advanced querying and data manipulation. I've mostly used them in PostgreSQL. |
- | I don't have any examples of code, but I have an uncompleted [[lds-scriptures.js|Javascript project]] where I use them a lot. | + | I don't have any examples of code, but I have an uncompleted [[lds-scriptures.js|Javascript project]] where I use them. |
Here's some code that is a regular expression that will do forward and reverse lookups for "Book Chapter Verse(s)" ranges. This is Javascript here, but the patterns themselves won't change. | Here's some code that is a regular expression that will do forward and reverse lookups for "Book Chapter Verse(s)" ranges. This is Javascript here, but the patterns themselves won't change. | ||
+ | |||
+ | The context here is not related to the databases, but to examine a source of text data and find the strings that match. | ||
<code> | <code> | ||
+ | var p_book_titles = "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|Solomon's Song|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|1 Nephi|2 Nephi|Jacob|Enos|Jarom|Omni|Words of Mormon|Mosiah|Alma|Helaman|3 Nephi|4 Nephi|Mormon|Ether|Moroni|Doctrine and Covenants|Moses|Abraham|Joseph Smith--Matthew|Joseph Smith--History|Articles of Faith"; | ||
+ | |||
+ | var p_book_short_titles = "Gen.|Ex.|Lev.|Num.|Deut.|Josh.|Judg.|Ruth|1 Sam.|2 Sam.|1 Kgs.|2 Kgs.|1 Chr.|2 Chr.|Ezra|Neh.|Esth.|Job|Ps.|Prov.|Eccl.|Song.|Isa.|Jer.|Lam.|Ezek.|Dan.|Hosea|Joel|Amos|Obad.|Jonah|Micah|Nahum|Hab.|Zeph.|Hag.|Zech.|Mal.|Matt.|Mark|Luke|John|Acts|Rom.|1 Cor.|2 Cor.|Gal.|Eph.|Philip.|Col.|1 Thes.|2 Thes.|1 Tim.|2 Tim.|Titus|Philem.|Heb.|James|1 Pet.|2 Pet.|1 Jn.|2 Jn.|3 Jn.|Jude|Rev.|1 Ne.|2 Ne.|Jacob|Enos|Jarom|Omni|W of M|Mosiah|Alma|Hel.|3 Ne.|4 Ne.|Morm.|Ether|Moro.|D&C|Moses|Abr.|JS-M|JS-H|A of F"; | ||
+ | |||
// Find all the range strings | // Find all the range strings | ||
var pattern = ""; | var pattern = ""; |