PHP preg_match bible scripture format

前端 未结 5 1423
眼角桃花
眼角桃花 2020-12-09 20:14

I am struggling with building a regular expression for parsing this kind of strings (bible scriptures):

  \'John 14:16–17, 25–26\'
  \'John 14:16–17\'
  \'Jo         


        
5条回答
  •  隐瞒了意图╮
    2020-12-09 21:08

       (\b[a-zA-Z]\w+\s\d+)(:\d+)+([-–]\d+)?([,;](\s)?(\d+:)?\d+([-–]\d+)?)?
    

    This is a hybrid of all code presented here. The only formats it will not highlight are "book name only" or "book & chapter only" (just add ":1-all" after chapter #) I found the other codes provided to qualify too many variations, not in line with bible verse syntax.

    These are the examples I tested in RegExr: (can't post images yet)

    John humbolt 14:16–17, 25–26
    John 14:16–17
    John 14:16
    John 77:3; 2:9-11
    John 5:1-all brad 555-783-6867
    John 6
    hi there how are you
    Ezra 32:5 John 14:16-17, 25-36
    12 23:34
    John 14:16-17,25-36
    John 14:16-17; 32:25

提交回复
热议问题