use strict;
my $str = '4 out of 6.0
2.979 out of 4 gpa
out of 5
gpa 3.712 out of 4
110 out of 110
4.94 (for second part) out of 6
9.45 points out of 10 (240 ects)
5.7 out of 7.
cgpa- 3.66 out of 4
a-/gpa :3.55 out of 4.00
4.5 out of a possible 5
a4 19 out of 22
1.15 1 being the best grade out of 5
3.64out of 6
28 out of 30. final grade 108 out of 110
2.64out of 4 average 74.02%
81.77. gpa:3.7out of 4.3
81.77gpa:3.7 out of 1.3
cumulative gpa 16.22out of 20.00
9.13 rank 20 out of 80
a+/9.65 out of 10
3.6/4 or 17.87 out of 20
87.1%/gpa 3.71 out of 5.0';
my $regex = qr/[a-z0-9 %\-\+:\/]*\b(\d{1,3}\.?\d{0,4})\.?[a-z0-9 \(\)]*out of[a-z ]*(\d{1,3}\.?\d{0,4})\.?.*/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