作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我看到这个:PHP preg_match bible scripture format
但我的问题有点不同,因为我想提取那些元素,而不仅仅是匹配它们。而我的模式更复杂:
'John 14:16–17, 25–26'
'John 14:16–17'
'John 14:16'
'John 14 16'
'John 14:16'
'John14 : 16'
'John 14 16'
'John14: 16'
'John14:16—17'
'John14 16 17'
'John14 : 16 17'
'John14 : 16 — 17'
'John 14 16 17'
'约翰福音 14 16 17' -> here is an actual example of unicode text
还应该考虑'-'、':'和' '是全角或半角字符,例如'-'、':'和'∀',我的意思是两者都应该有效。
我想要的是提取John(应该支持unicode)、14、16和17(如果存在)这些元素。
我试过:
$str = '10 : 12 — 15 % 52 .633 __+_+)_01(&( %&@#32$%!85#@60$';
preg_match_all('/[\d]+?/isU',$str, $t);
效果不是很好。
然后我尝试了:
preg_match_all("([\u4e00-\u9fa5]+)[^\d\n]*(\d+)[^\d\n]*(\d+)[^\d\n]*(\d*)", "John 14:16", $out);
var_dump($out);
同样无效。
好的,我找到了解决方案,它有效,但我不确定它是否 100% 正确:
preg_match_all('#([\x{4e00}-\x{9fa5}]+)[^\d\n]*(\d+)[^\d\n]*(\d+)[^\d\n]*(\d*)#u', $keyword, $match);
最佳答案
^(\p{L}+)?\s*(\d+)?[\p{Pd}\p{Zs}:]*(\d+)?[\p{Pd}\p{Zs}:]*(\d+)?
你需要 \p{L}
来匹配 unicode 字符。
\p{Zs}
表示任何类型的空格,\p{Pd}
表示任何类型的破折号或连字符。
preg_match_all("/^(\p{L}+)?\s*(\d+)?[\p{Pd}\p{Zs}:]*(\d+)?[\p{Pd}\p{Zs}:]*(\d+)?/m", "John 14:16", $out);
var_dump($out);
关于php - 如何在 PHP 中通过正则表达式提取圣经书名、章节和经文编号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20875727/
Book_title Table +---------------+-------------------+ | isbn | title | +------
如何删除 PHP 中的所有 HTML 标记,除了 <>人物? //There's other HTML tags, like h1, div, etc. echo strip_tags(' a hot
我是一名优秀的程序员,十分优秀!