re = /((?<=\()\S+(?=%\))|^\S+(?=\s\[))/m
str = '0
1991 (38.26%)
1018 (41.52%)
438 (35.12%)
771 (35.16%)
244 (35.72%)
343 (32.48%)
316 (40.51%)
177 (33.84%)
133 (41.18%)
792 (35.92%)
3190 (61.30%)
1426 (58.16%)
803 (64.39%)
1415 (64.52%)
436 (63.84%)
711 (67.33%)
463 (59.36%)
345 (65.97%)
187 (57.89%)
1403 (63.63%)
44.00 [38.00 - 50.00]
43.00 [37.00 - 49.00]
43.00 [37.00 - 49.00]
44.00 [38.00 - 50.00]
44.00 [39.00 - 50.00]
44.00 [38.00 - 50.00]
43.00 [37.00 - 49.00]
45.00 [39.00 - 51.00]
44.00 [37.00 - 50.00]
45.00 [38.00 - 51.00]
'
# 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