use strict;
my $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\'
}
';
my $regex = qr/((RESERVADAS|[A-Z]+)[(][)][ ]*[\t]*[\r\n|\n]*([{][\r\n|\n]*([\t]*[ ]*[0-9]+[ ]*[=][ ]*(['][A-Z]+['])[\r\n|\n]*)+[\r\n|\n]*[}][\r\n|\n]*)*)/mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
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 Perl, please visit: http://perldoc.perl.org/perlre.html