$re = '/^(?:time=\"(?<longtime>\d{4}-\d{2}-\d{2}\D{1}\d{2}:\d{2}:\d{2}\+\d{2}:\d{2})\") (?:level=(?<level>(info|warn|error))) (?:msg=\"(?<msg>.*)\") (((?:duration=(?<duration>\d{1,9}.\d{1,9})) (?:gitaly_embedded=(?<gitaly_embedded>[^ ]+)) (?:method=(?<method>(POST|GET))))|((?:body="(?<body>.*)") (?<code>code=\d{3}) (?:method=(?<method2>(POST|GET)))|(?<command>command=".*"))|(?:key_id=key-(?<key_id>)\d{3})) (?:pid=(?<pid>\d{1,5})) (?:url=\"(((?<url>.*)\"))|(?:user="(?<user>.*)")|(?:public_key="(?<public_key>.*)"))/m';
$str = 'time="2019-06-10T09:23:34+03:00" level=info msg="finished HTTP request" duration=0.02119909 gitaly_embedded=false method=POST pid=45053 url="http://127.0.0.1:8080/api/v4/internal/allowed"
time="2019-06-10T09:23:34+03:00" level=info msg="executing git command" command="gitaly-upload-pack unix:/var/opt/gitlab/gitaly/gitaly.socket {\\"repository\\":{\\"storage_name\\":\\"default\\",\\"relative_path\\":\\"internet_platform/auto_tests.git\\",\\"git_object_directory\\":\\"\\",\\"git_alternate_object_directories\\":[],\\"gl_repository\\":\\"project-548\\",\\"gl_project_path\\":\\"internet_platform/auto_tests\\"},\\"gl_repository\\":\\"project-548\\",\\"gl_project_path\\":\\"internet_platform/auto_tests\\",\\"gl_id\\":\\"key-147\\",\\"gl_username\\":\\"Ext-Y.Korop\\",\\"git_config_options\\":[],\\"git_protocol\\":null}" pid=45053 user="user with id key-147"
time="2019-06-10T09:23:38+03:00" level=info msg="finished HTTP request" duration=0.021129036 gitaly_embedded=false method=POST pid=45077 url="http://127.0.0.1:8080/api/v4/internal/allowed"
time="2019-06-10T09:23:38+03:00" level=info msg="executing git command" command="gitaly-upload-pack unix:/var/opt/gitlab/gitaly/gitaly.socket {\\"repository\\":{\\"storage_name\\":\\"default\\",\\"relative_path\\":\\"erl-omsk/eps-storage-web.git\\",\\"git_object_directory\\":\\"\\",\\"git_alternate_object_directories\\":[],\\"gl_repository\\":\\"project-1375\\",\\"gl_project_path\\":\\"erl-omsk/eps-storage-web\\"},\\"gl_repository\\":\\"project-1375\\",\\"gl_project_path\\":\\"erl-omsk/eps-storage-web\\",\\"gl_id\\":\\"key-147\\",\\"gl_username\\":\\"Ext-Y.Korop\\",\\"git_config_options\\":[],\\"git_protocol\\":null}" pid=45077 user="user with id key-147"
time="2019-06-10T09:23:42+03:00" level=info msg="finished HTTP request" duration=0.021581528 gitaly_embedded=false method=POST pid=45169 url="http://127.0.0.1:8080/api/v4/internal/allowed"
time="2019-06-10T09:23:42+03:00" level=info msg="executing git command" command="gitaly-upload-pack unix:/var/opt/gitlab/gitaly/gitaly.socket {\\"repository\\":{\\"storage_name\\":\\"default\\",\\"relative_path\\":\\"erl-omsk/smev-fssp.git\\",\\"git_object_directory\\":\\"\\",\\"git_alternate_object_directories\\":[],\\"gl_repository\\":\\"project-63\\",\\"gl_project_path\\":\\"erl-omsk/smev-fssp\\"},\\"gl_repository\\":\\"project-63\\",\\"gl_project_path\\":\\"erl-omsk/smev-fssp\\",\\"gl_id\\":\\"key-147\\",\\"gl_username\\":\\"Ext-Y.Korop\\",\\"git_config_options\\":[],\\"git_protocol\\":null}" pid=45169 user="user with id key-147"
time="2019-06-10T09:23:44+03:00" level=info msg="finished HTTP request" duration=0.022346368 gitaly_embedded=false method=POST pid=45236 url="http://127.0.0.1:8080/api/v4/internal/allowed"
time="2019-06-10T09:23:44+03:00" level=error msg="Call failed" body="{\\"status\\":false,\\"message\\":\\"Your account has been blocked.\\"}" code=401 method=POST pid=45236 url="http://127.0.0.1:8080/api/v4/internal/allowed"
time="2019-06-10T09:23:44+03:00" level=warn msg="Access denied" command="git-upload-pack \'kubernetes/heapster-k8s-config.git\'" pid=45236 user="user with id key-18"
time="2019-06-10T09:23:46+03:00" level=info msg="finished HTTP request" duration=0.019885438 gitaly_embedded=false method=POST pid=45308 url="http://127.0.0.1:8080/api/v4/internal/allowed"
time="2019-06-10T09:23:46+03:00" level=info msg="executing git command" command="gitaly-upload-pack unix:/var/opt/gitlab/gitaly/gitaly.socket {\\"repository\\":{\\"storage_name\\":\\"default\\",\\"relative_path\\":\\"erl-omsk/eps-mail-receiver.git\\",\\"git_object_directory\\":\\"\\",\\"git_alternate_object_directories\\":[],\\"gl_repository\\":\\"project-814\\",\\"gl_project_path\\":\\"erl-omsk/eps-mail-receiver\\"},\\"gl_repository\\":\\"project-814\\",\\"gl_project_path\\":\\"erl-omsk/eps-mail-receiver\\",\\"gl_id\\":\\"key-147\\",\\"gl_username\\":\\"Ext-Y.Korop\\",\\"git_config_options\\":[],\\"git_protocol\\":null}" pid=45308 user="user with id key-147"
time="2019-06-10T09:23:51+03:00" level=info msg="finished HTTP request" duration=0.025155263 gitaly_embedded=false method=POST pid=45461 url="http://127.0.0.1:8080/api/v4/internal/allowed"
time="2019-06-10T09:23:51+03:00" level=info msg="executing git command" command="gitaly-upload-pack unix:/var/opt/gitlab/gitaly/gitaly.socket {\\"repository\\":{\\"storage_name\\":\\"default\\",\\"relative_path\\":\\"erl-omsk/eps-api.git\\",\\"git_object_directory\\":\\"\\",\\"git_alternate_object_directories\\":[],\\"gl_repository\\":\\"project-906\\",\\"gl_project_path\\":\\"erl-omsk/eps-api\\"},\\"gl_repository\\":\\"project-906\\",\\"gl_project_path\\":\\"erl-omsk/eps-api\\",\\"gl_id\\":\\"key-147\\",\\"gl_username\\":\\"Ext-Y.Korop\\",\\"git_config_options\\":[],\\"git_protocol\\":null}" pid=45461 user="user with id key-147"
time="2019-06-10T09:23:53+03:00" level=info msg="finished HTTP request" duration=0.0159927 gitaly_embedded=false method=POST pid=45550 url="http://127.0.0.1:8080/api/v4/internal/allowed"
time="2019-06-10T09:23:53+03:00" level=info msg="executing git command" command="gitaly-upload-pack unix:/var/opt/gitlab/gitaly/gitaly.socket {\\"repository\\":{\\"storage_name\\":\\"default\\",\\"relative_path\\":\\"uksz/as-ss-stub.git\\",\\"git_object_directory\\":\\"\\",\\"git_alternate_object_directories\\":[],\\"gl_repository\\":\\"project-1644\\",\\"gl_project_path\\":\\"uksz/as-ss-stub\\"},\\"gl_repository\\":\\"project-1644\\",\\"gl_project_path\\":\\"uksz/as-ss-stub\\",\\"gl_id\\":\\"key-580\\",\\"gl_username\\":\\"Ext-A.P.Kosarenko\\",\\"git_config_options\\":[],\\"git_protocol\\":null}" pid=45550 user="user with id key-580"
time="2019-06-10T09:23:54+03:00" level=info msg="finished HTTP request" duration=0.014709537 gitaly_embedded=false method=POST pid=45593 url="http://127.0.0.1:8080/api/v4/internal/allowed"
time="2019-06-10T09:23:54+03:00" level=error msg="Call failed" body="{\\"status\\":false,\\"message\\":\\"Your account has been blocked.\\"}" code=401 method=POST pid=45593 url="http://127.0.0.1:8080/api/v4/internal/allowed"
time="2019-06-10T09:23:54+03:00" level=warn msg="Access denied" command="git-upload-pack \'Docker/example.git\'" pid=45593 user="user with id key-18"
time="2019-06-10T09:23:55+03:00" level=info msg="finished HTTP request" duration=0.020508204 gitaly_embedded=false method=POST pid=45669 url="http://127.0.0.1:8080/api/v4/internal/allowed"
time="2019-06-10T09:23:55+03:00" level=info msg="executing git command" command="gitaly-upload-pack unix:/var/opt/gitlab/gitaly/gitaly.socket {\\"repository\\":{\\"storage_name\\":\\"default\\",\\"relative_path\\":\\"erl-omsk/eps-digital-signature.git\\",\\"git_object_directory\\":\\"\\",\\"git_alternate_object_directories\\":[],\\"gl_repository\\":\\"project-785\\",\\"gl_project_path\\":\\"erl-omsk/eps-digital-signature\\"},\\"gl_repository\\":\\"project-785\\",\\"gl_project_path\\":\\"erl-omsk/eps-digital-signature\\",\\"gl_id\\":\\"key-147\\",\\"gl_username\\":\\"Ext-Y.Korop\\",\\"git_config_options\\":[],\\"git_protocol\\":null}" pid=45669 user="user with id key-147"';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php