PHP preg_match bible scripture format

前端 未结 5 1446
眼角桃花
眼角桃花 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 20:52

    Use this regex :

    [A-Za-z]+( ([0-9]+)(:[0-9]+)?([\-–][0-9]+)?(, [0-9]+[\-–][0-9]+)?)?
    

    Or in its 'prettier' version :

    \w+( (\d+)(:\d+)?([\-–]\d+)?(, \d+[\-–]\d+)?)?
    

    UPDATED : To match dashes or hyphens


    NOTE : I've tested it and it matches ALL 5 possible versions.

    Example : http://regexr.com?30h4q

    enter image description here

提交回复
热议问题