Php Regex-在每个日期时间拆分字符串

Php Regex-在每个日期时间拆分字符串,php,regex,Php,Regex,每次有时间戳时,我都试图将从提要中获取的更新字符串拆分为一个数组 这是我到目前为止使用的正则表达式,但它似乎只在字符串中找到第一个datetime ^(\d{1,2}\/\d{1,2}\/\d{4}) 下面是我的字符串的一个示例 $Comment = "8/13/2015 11:44:10 AMVN - Upon additional underwriting review. Account will be declined due to inconsistencies in personal

每次有时间戳时,我都试图将从提要中获取的更新字符串拆分为一个数组

这是我到目前为止使用的正则表达式,但它似乎只在字符串中找到第一个datetime

^(\d{1,2}\/\d{1,2}\/\d{4})
下面是我的字符串的一个示例

$Comment = "8/13/2015 11:44:10 AMVN - Upon additional underwriting review. Account will be declined due to inconsistencies in personal and/or business information that can not be verified or validated 8/13/2015 8:32:52 AMFA Rcvd Change In Terms letter, will fwd to the Underwriter. 8/10/2015 1:21:17 PMVN - Please provide change in term letter capping monthly volume $20K, average ticket to $500 and high ticket to $1K. 8/10/2015 11:02:19 AMVN Declined as the financial condition do not support business type and requested limits. 8/10/2015 9:37:03 AMFA Rcvd Bank Statements, will fwd to the Underwriter. 8/4/2015 3:35:05 PMVN - Please provide 3 most recent bank statements and 3 most recent processing statements. 8/4/2015 9:52:04 AMBAI In Underwriting iEntry Application";
使用这个例子,我想要一个有七个值的数组

$Pattern = "^(\d{1,2}\/\d{1,2}\/\d{4})";
$Comments = preg_split($Pattern, $Comment);

不要将它锚定到字符串的开头,因此要去掉
^

(\d{1,2}\/\d{1,2}\/\d{4})

当您需要在一个日期串上拆分一个没有字符串中断的长字符串时,可以考虑< <强> > ReX拆分< /强>方法>

\s+(?=<DATE_PATTERN HERE>)              # DATE is preceded with whitespace, anything can follow
\s+(?=<DATE_PATTERN HERE>\b)            # DATE is preceded with whitespace, date is not followed with letter/digit/_
\s*(?<!\d)(?=<DATE_PATTERN HERE>)       # Whitespace before date optional, no digit before
\s*(?<!\d)(?=<DATE_PATTERN HERE>)(?!\d) # Whitespace before date optional, no digit before and after
\s*(?<!\d)(?<!\d<DEL>)(?=<DATE_PATTERN HERE>)(?!<DEL>?\d) # Whitespace before date optional, no digit with delimiter before and after
见:

输出:

Array
(
    [0] => 8/13/2015 11:44:10 AMVN - Upon additional underwriting review. Account will be declined due to inconsistencies in personal and/or business information that can not be verified or validated
    [1] => 8/13/2015 8:32:52 AMFA Rcvd Change In Terms letter, will fwd to the Underwriter.
    [2] => 8/10/2015 1:21:17 PMVN - Please provide change in term letter capping monthly volume $20K, average ticket to $500 and high ticket to $1K.
    [3] => 8/10/2015 11:02:19 AMVN Declined as the financial condition do not support business type and requested limits.
    [4] => 8/10/2015 9:37:03 AMFA Rcvd Bank Statements, will fwd to the Underwriter.
    [5] => 8/4/2015 3:35:05 PMVN - Please provide 3 most recent bank statements and 3 most recent processing statements.
    [6] => 8/4/2015 9:52:04 AMBAI In Underwriting iEntry Application
)

您的正则表达式没有分隔符,因此它永远不会在PHP中运行。
$Comment = "8/13/2015 11:44:10 AMVN - Upon additional underwriting review. Account will be declined due to inconsistencies in personal and/or business information that can not be verified or validated 8/13/2015 8:32:52 AMFA Rcvd Change In Terms letter, will fwd to the Underwriter. 8/10/2015 1:21:17 PMVN - Please provide change in term letter capping monthly volume $20K, average ticket to $500 and high ticket to $1K. 8/10/2015 11:02:19 AMVN Declined as the financial condition do not support business type and requested limits. 8/10/2015 9:37:03 AMFA Rcvd Bank Statements, will fwd to the Underwriter. 8/4/2015 3:35:05 PMVN - Please provide 3 most recent bank statements and 3 most recent processing statements. 8/4/2015 9:52:04 AMBAI In Underwriting iEntry Application";
$records = preg_split('~\s+(?=\d{1,2}/\d{1,2}/\d{4})~', $Comment);
print_r($records);
Array
(
    [0] => 8/13/2015 11:44:10 AMVN - Upon additional underwriting review. Account will be declined due to inconsistencies in personal and/or business information that can not be verified or validated
    [1] => 8/13/2015 8:32:52 AMFA Rcvd Change In Terms letter, will fwd to the Underwriter.
    [2] => 8/10/2015 1:21:17 PMVN - Please provide change in term letter capping monthly volume $20K, average ticket to $500 and high ticket to $1K.
    [3] => 8/10/2015 11:02:19 AMVN Declined as the financial condition do not support business type and requested limits.
    [4] => 8/10/2015 9:37:03 AMFA Rcvd Bank Statements, will fwd to the Underwriter.
    [5] => 8/4/2015 3:35:05 PMVN - Please provide 3 most recent bank statements and 3 most recent processing statements.
    [6] => 8/4/2015 9:52:04 AMBAI In Underwriting iEntry Application
)