多数のトレースを含むログ ファイルを解析しようとしていますが、その一部には複数の行が含まれています。
例:
[trace-123] <request>This is a log line</request>
[trace-124] <reply>This is another log line
this is part of "[trace-124]" still.</reply>
[trace-125] <request>final log line.</request>
すべてのトレースの配列を取得するために preg_match_all を使用しようとしています。
$file = file_get_contents("traces.txt");
$tracePattern = "/(\[trace-[0-9]*+\]+[\s\S]*)(?<=\<\/reply>|\<\/request>)/";
preg_match_all($tracePattern,$file,$lines);
echo "<pre>";print_r($lines);echo "</pre>";
理想的には、結果が次のようになることを望みます。
Array
(
[0] => [trace-123] <request>This is a log line</request>
[1] => [trace-124] <reply>This is another log line
this is part of "[trace-124]" still.</reply>
[2] => [trace-125] <request>final log line.</request>
)
しかし、実行すると、配列の1つの要素にすべてが含まれる配列が得られます。式を書いたときの目標は、基本的に次のものを探すことでした。
[trace-\[0-9]*\]
その試合から次の試合までのすべてを見つけます。
見つけた
\[trace-[0-9]*+\].*
かなりうまく機能しますが、改行があると機能しなくなります。