在 php 中用句号拆分字符串,排除 "a.m."

Split string by full stop in php exclude "a.m."

我正在使用 PHP 中的 preg_split 函数将一个段落拆分为几个句子。

就我而言:

$str = 'Applicants can check the final result of Admissions through the online enquiry system. The online enquiry system will be available from 10:00 a.m. on November 16 (Wednesday).';

$arr = preg_split('/\./', $str);

a.m.p.m.时如何排除?

您应该能够使用 (*SKIP)(*FAIL) 来阻止 am/pm 匹配。您可以在此处阅读有关该方法的更多信息,http://www.rexegg.com/regex-best-trick.html

[ap]\.m\.(*SKIP)(*FAIL)|\.

正则表达式演示:https://regex101.com/r/uD9xD7/1

演示:https://eval.in/548705

PHP 用法:

$str = 'Applicants can check the final result of Admissions through the online enquiry system. The online enquiry system will be available from 10:00 a.m. on November 16 (Wednesday).';

$arr = preg_split('/[ap]\.m\.(*SKIP)(*FAIL)|\./', $str);

print_r($arr);

输出:

Array
(
    [0] => Applicants can check the final result of Admissions through the online enquiry system
    [1] =>  The online enquiry system will be available from 10:00 a.m. on November 16 (Wednesday)
    [2] => 
)

如果 A.M. 也应该允许使用 i modifier.