3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = [ 'new message from Bob [22:105:3905:534]', 'user Dylan posted a question in section General', 'new message from Mary(gold) [19504:8728:18524:78941]' ]; $formats = [ '/new message from (\w+) \[(\d+):(\d+):(\d+):(\d+)\]/', // this would actually be something like '/(?<=new message from )(.*)(?=[)(.*)(?=:)(.*)(?=:)(.*)(?=:)(.*)(?=])/' '/user (\w+) posted a question in section ([\w ]+)/', '/new message from (\w+)\((\w+)\) \[(\d+):(\d+):(\d+):(\d+)\]/', ]; foreach ($input as $line) { foreach ($formats as $key => $format) { $data = []; if (preg_match($format, $line, $data)) { array_shift($data); echo 'format: ' . $key . ', data: ' . var_export($data, true) . "\n"; continue; } } }

preferences:
40.91 ms | 402 KiB | 5 Q