$re = '/((RESERVADAS|[A-Z]+)[(][)][ ]*[\t]*[\r\n|\n]*([{][\r\n|\n]*([\t]*[ ]*[0-9]+[ ]*[=][ ]*([\'][A-Z]+[\'])[\r\n|\n]*)+[\r\n|\n]*[}][\r\n|\n]*)*)/m';
$str = 'RESERVADAS()
{
18 = \'PROGRAM\'
19 = \'INCLUDE\'
20 = \'CONST\'
21 = \'TYPE\'
22 = \'VAR\'
23 = \'RECORD\'
24 = \'ARRAY\'
25 = \'OF\'
26 = \'PROCEDURE\'
27 = \'FUNCTION\'
28 = \'IF\'
29 = \'THEN\'
30 = \'ELSE\'
31 = \'FOR\'
32 = \'TO\'
33 = \'WHILE\'
34 = \'DO\'
35 = \'EXIT\'
36 = \'END\'
37 = \'CASE\'
38 = \'BREAK\'
39 = \'DOWNTO\'
}
COSO()
{
19=\'A\'
}
';
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