use strict;
my $str = 'avg() of query(wpFnYRwGk/2/bitrate, 15m, now) is below(14)
avg() of query(wpFnYRwGk/2/bitrate, 15m, now) is below(0.4)
avg() of query(wpFnYRwGk/2/bitrate, 15m, now) is novalue()
avg() of query(wpFnYRwGk/2/bitrate, 15m, now) is withinrange(4, 88)
avg() of query(wpFnYRwGk/2/bitrate, 15m, now) is withinrange(4, 88) for (1m)
avg() of query(wpFnYRwGk/2/bitrate, 15m, now) is withinrange(4, 88) for (1m) every(1m)
avg() of query(summary/152/tx-avg, 1m, now) is below(5000)
avg() of query(summary/152/tx-avg, 1m, now) is below(-5000)
avg() of query(wpFnYRwGk/2/bitrate, 15m, now) is above(300M)';
my $regex = qr`^(?P<reducer>\w+)\(\)\s+of\s+query\((?P<dashboardUID>\w+)\/(?P<panelID>\d+)\/(?P<metric>.+),\s+(?P<from>\w+),\s+(?P<to>\w+)\)\s+is\s+(?P<evaluator>\w+)\((?P<params>-*\d*[\.,\s]*\d*\w*)\)\s*(for\s+\((?P<for>\w+)\))*\s*(every\((?P<every>\w+)\))*\s*$`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