我在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.
?
答案 0 :(得分:0)
您应该可以使用(*SKIP)(*FAIL)
来阻止am/pm
次匹配。您可以在此处详细了解该方法,http://www.rexegg.com/regex-best-trick.html。
[ap]\.m\.(*SKIP)(*FAIL)|\.
正则表达式演示:https://regex101.com/r/uD9xD7/1
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。