$re = '/(?xim)
^ # BOL
(?P<path>..[^:]*) # path
:: # two colons
(?:(?P<warning>WARN)|(?P<error>ERROR)) # WARN or ERROR
:: # two colons
\s # whitespace
\( # left brace
\s* # optional whitespace
(?P<line>[0-9]+) # named group: line
, # comma
\s* # optional whitespace
(?P<col>[0-9]+) # named group: col
\) # right brace
\: # colon
\s # whitespace
(?P<message>.*) # named group: message
$ # EOL
/m';
$str = '/Users/bb/Downloads/test.lsl::ERROR:: ( 5, 30): syntax error, unexpected \',\'
TOTAL:: Errors: 1 Warnings: 0
C:\\Users\\bb\\Downloads\\test.lsl::ERROR:: ( 5, 30): syntax error, unexpected \',\'
TOTAL:: Errors: 1 Warnings: 0';
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