Reputation: 2654
How can I extract the date from these two strings.
Date: 03/03 - 14:10
text
And from
Date/Time: 08/03/16 13:50
Summary of Fault:
I have tried
$matches = array();
$pattern = "/^.*\Date\/Time\:\b.*$/m";
preg_match($pattern, $toParse, $matches);
echo($matches[0]);
$matches = array();
$pattern = "/.*Date:.*/mi";
preg_match($pattern, $toParse, $matches);
Upvotes: 1
Views: 342
Reputation: 343
You have to use preg_match_all
'/: (.*?) /'
https://regex101.com/r/tY6bT5/1
Upvotes: 0
Reputation: 2510
First of all, in order to extract all the matched occurrences, you need to use preg_match_all()
.
Pattern for time:
/.[0-9]:.[0-9]/
Patern for Date:
/.[0-9]\/.[0-9]\/.[0-9]/
Here is a reference to preg_match_all
Upvotes: 1