在php exclude中用句号分割字符串“;上午”;


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)|'.

Regex演示: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修饰符。