re = /(?=Table \d+\.)/m
str = '4 BLABLA\\r\\n Table 1. Real GDP\\r\\n Percentage changes\\r\\n 2016 2017 \\r\\nArgentina -2.5 2.7\\r\\nAustralia 2.6 2.5\\r\\n BLABLA \\r\\n Table 2. Nominal GDP\\r\\n Percentage changes\\r\\n 2011 2012\\r\\nArgentina 31.1 21.1\\r\\nAustralia 7.7 3.3\\r\\n'
subst = '\\n\\n\\n'
result = str.gsub(re, subst)
# Print the result of the substitution
puts result
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