Since your last bracket is using laziness mark with wildcard, it will match nothing except other rules require it to. There is no other rules to specify the end of the overall match, so the last part sami
is simply skipped by your regular expression. You can examine this:
<?php
$data="Date:29-05-2016 11:36 - Mo:919530489323 - pdd:9339 - lpm:78JIOP - pas:sami";
preg_match('#Date:(.*?) (.*?) - Mo:91(.*?) - pdd:(.*?) - lpm:(.*?) - pas:(.*?)#',$data,$matches);
var_dump($matches);
Which output this:
array(7) {
[0]=>
string(70) "Date:29-05-2016 11:36 - Mo:919530489323 - pdd:9339 - lpm:78JIOP - pas:"
[1]=>
string(10) "29-05-2016"
[2]=>
string(5) "11:36"
[3]=>
string(10) "9530489323"
[4]=>
string(4) "9339"
[5]=>
string(6) "78JIOP"
[6]=>
string(0) ""
}
Notice the overall matching string ($matches[0]
) value actually stops at the last :
. that's why you have an empty string in $matches[6]
.
Chainging the regular expression will fix the issue:
<?php
$data="Date:29-05-2016 11:36 - Mo:919530489323 - pdd:9339 - lpm:78JIOP - pas:sami";
preg_match('#^Date:(.*?) (.*?) - Mo:91(.*?) - pdd:(.*?) - lpm:(.*?) - pas:(.*?)$#',$data,$matches);
var_dump($matches);
Notice the ^
and $
I've added. They will match "the beginning of string" and "the end of string". So the string from the last :
to the end of whole input string will be included. Which output this:
array(7) {
[0]=>
string(74) "Date:29-05-2016 11:36 - Mo:919530489323 - pdd:9339 - lpm:78JIOP - pas:sami"
[1]=>
string(10) "29-05-2016"
[2]=>
string(5) "11:36"
[3]=>
string(10) "9530489323"
[4]=>
string(4) "9339"
[5]=>
string(6) "78JIOP"
[6]=>
string(4) "sami"
}