1

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);
shorif2000
  • 2,582
  • 12
  • 65
  • 137

2 Answers2

1

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

Panda
  • 2,400
  • 3
  • 25
  • 35
0

You have to use preg_match_all

'/: (.*?) /'

https://regex101.com/r/tY6bT5/1

smallbee
  • 233
  • 1
  • 4
  • 16