PHP preg_match圣经经文格式 [英] PHP preg_match bible scripture format

查看:111
本文介绍了PHP preg_match圣经经文格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力构建用于解析此类字符串(圣经经文)的正则表达式:

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'
  'John 14:16'
  'John 14'
  'John'

所以基本模式是:

Book [[Chapter][:Verse]]

其中章节和经文是可选的.

where chapter and verse is optional.

推荐答案

在此处尝试

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

在Regexr上查看并对其进行测试

由于(?:,\s*\d+(?:–\d+)?)*位于末尾,因此您可以列出一首经文,末尾的经文范围.

Because of the (?:,\s*\d+(?:–\d+)?)* at the end you can have a list of verses, verses ranges at the end.

这篇关于PHP preg_match圣经经文格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆