我一直在尝试创建一个正则表达式来拆分各种经文引用。
这是我到目前为止得到的:
$split_references = preg_split("/((, | or | and ))[^0-9(]/i", $reference);
这可能需要处理的文本示例是:
创世记1:1-2:4a和诗篇136:1-9,23-26,创世记7:1-5,11-18;8:6-18;9:8-13和诗篇46,创世记22:1-18和诗篇16,出埃及记14:10-31;15:20-21和出埃及记15:1b-13,17-18,以赛亚书55:1-11和 以赛亚书12:2-6,巴录3:9-15,3:32-4:4或箴言8:1-8,19-21;9:4b-6和诗篇19,以西结书36:24-28和诗篇42,43,以西结书37:1-14和诗篇143,西番雅书3:14-20和诗篇98创世记1:1-2:4a和诗篇136:1-9,23-26,创世记7:1-5,11-18;8:6-18;9:8-13和诗篇46,创世记22:1-18和诗篇16,出埃及记14:10-31;15:20-21和出埃及记15:1b-13,17-18,以赛亚书55:1-11和以赛亚书12:2-6,巴录3:9-15,3:32-4:4或箴言8:1-8,19-21;9:4b-6和诗篇19,以西结书36:24-28和诗篇42,43,以西结书37:1-14和诗篇143,西番雅书3:14-20和诗篇98
我目前得到的结果类型是:
Array(
[0] => Genesis 1:1-2:4a
[1] => salm 136:1-9, 23-26
[2] => enesis 7:1-5, 11-18; 8:6-18; 9:8-13
[3] => salm 46
[4] => enesis 22:1-18
[5] => salm 16
[6] => xodus 14:10-31; 15:20-21
[7] => xodus 15:1b-13, 17-18
[8] => saiah 55:1-11
[9] => saiah 12:2-6
[10] => aruch 3:9-15, 3:32-4:4
[11] => roverbs 8:1-8, 19-21; 9:4b-6
[12] => salm 19
[13] => zekiel 36:24-28
[14] => salm 42, 43
[15] => zekiel 37:1-14
[16] => salm 143
[17] => ephaniah 3:14-20
[18] => salm 98
)
注意到第一个字母被切断了吗?我正在尝试匹配 [逗号字母] 以防止在 [逗号诗句] 上破坏数组
感谢您提供的任何指导! :)
杰森·西尔弗
使用前瞻:
$split_references = preg_split("/((, | or | and ))(?=[^0-9(])/i", $reference);
这说"不跟着这些字符之一",而不"消耗"这些字符。替代(相同 - 但消极的展望,而不是消极的对负字符类的正面展望):
$split_references = preg_split("/((, | or | and ))(?!=[0-9(])/i", $reference);
上述结果:
Array
(
[0] => Genesis 1:1-2:4a
[1] => Psalm 136:1-9, 23-26
[2] => Genesis 7:1-5, 11-18; 8:6-18; 9:8-13
[3] => Psalm 46
[4] => Genesis 22:1-18
[5] => Psalm 16
[6] => Exodus 14:10-31; 15:20-21
[7] => Exodus 15:1b-13, 17-18
[8] => Isaiah 55:1-11
[9] => Isaiah 12:2-6
[10] => Baruch 3:9-15, 3:32-4:4
[11] => Proverbs 8:1-8, 19-21; 9:4b-6
[12] => Psalm 19
[13] => Ezekiel 36:24-28
[14] => Psalm 42, 43
[15] => Ezekiel 37:1-14
[16] => Psalm 143
[17] => Zephaniah 3:14-20
[18] => Psalm 98Genesis 1:1-2:4a
[19] => Psalm 136:1-9, 23-26
[20] => Genesis 7:1-5, 11-18; 8:6-18; 9:8-13
[21] => Psalm 46
[22] => Genesis 22:1-18
[23] => Psalm 16
[24] => Exodus 14:10-31; 15:20-21
[25] => Exodus 15:1b-13, 17-18
[26] => Isaiah 55:1-11
[27] => Isaiah 12:2-6
[28] => Baruch 3:9-15, 3:32-4:4
[29] => Proverbs 8:1-8, 19-21; 9:4b-6
[30] => Psalm 19
[31] => Ezekiel 36:24-28
[32] => Psalm 42, 43
[33] => Ezekiel 37:1-14
[34] => Psalm 143
[35] => Zephaniah 3:14-20
[36] => Psalm 98
)