re = /(?<=Code:).*Distribution\s([\d.,]+)(?=\n)/
str = 'Code: 210 - Test 1 - Distribution
267745 Vis - Branch Deposit 3/10/2021 2,000.00
468040 v- Branch Deposit 2/10/2021 1,700.00
586075 Visa 3/3/2021 555.48
502490 Vis 3/4/2021 1,835.51
403195 Vis 3/4/2021 2,033.56
500230 Vis 3/4/2021 651.29
Code: 210 - Test - Distribution 8,775.84
Code: 230 - Greenville - Distribution
853955 Clearing 2/1/2021 77.50'
# 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