I'm trying to split up a update string I get from a feed into an array each time there is a time stamp.
This is the regex I have so far, but it seems to only find the first datetime in the string.
^(\d{1,2}\/\d{1,2}\/\d{4})
Here is an example of my string.
$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";
Using this example, I would like to have an array with seven values.
$Pattern = "^(\d{1,2}\/\d{1,2}\/\d{4})";
$Comments = preg_split($Pattern, $Comment);
When you need to split a long string with no line breaks at a date string, you may consider a regex split method with
Here, you may use a simple
\s+(?=\d{1,2}/\d{1,2}/\d{4})
regex that matches 1+ whitespaces followed with (a(?=...)
is a positive lookaround that does not consume any text, just checks if there is a match and returns true or false) one or two digits,/
, one or two digits,/
and four digits:See the PHP demo:
Output:
Dont anchor it to the start of the string, hence get rid of the
^