I search before ask, but I what I've tested doesn't work. I have following string:
2016-07-31 00:32:29 debian-8gb-sfo2-01 gamed: notice :
I want to know how can I extract date from this string. The full regex (missing the date regex) returns the following:
Array
(
[0] => 2016-07-31 00:32:29 debian-8gb-sfo2-01 gamed: notice : formatlog:gshop_trade:userid=1792:db_magic_number=1744:order_id=23727:item_id=47494:expire=0:item_count=1:cash_need=1:cash_left=99976272:guid1=0:guid2=0
[1] => 2016-07-31 00:32:29 debian-8gb-sfo2-01 gamed: notice :
[2] => 1792
[3] => db_magic_number=1744:order_id=23727:
[4] => 47494
[5] => 0
[6] => 1
[7] => 1
[8] => 99976272
)
It's correct, but the desire output is:
Array
(
[1] => 2016-07-31 00:32:29
[2] => 1792
[3] => db_magic_number=1744:order_id=23727:
[4] => 47494
[5] => 0
[6] => 1
[7] => 1
[8] => 99976272
)
The current code:
if (strpos($line, 'gshop_trade:userid=1792:') > 0) {
if (!preg_match('/(.*)\sformatlog:gshop_trade:userid=(\d+):(.*)item_id=(\d+):expire=(\d+):item_count=(\d+):cash_need=(\d+):cash_left=(\d+).*$/', $line, $d)) {
// error occured
}
echo '<pre>';
print_r($d);
}
/\s*(\S+\s+\S+).*\sformatlog:gshop_trade:userid=(\d+):(.*)item_id=(\d+):expire=(\d+):item_count=(\d+):cash_need=(\d+):cash_left=(\d+).*$\K/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}|\b([^\W\d]+)\s*=\s*\K\d+?