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\'
}
'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html