re = /^(?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*)\)\s*(for\s+\((?P<for>\w+)\))*\s*(every\((?P<every>\w+)\))*\s*$/m
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)'
# 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