re = /instance\[(\d+)\]/m
str = 'hi everyone,
i\'d like to take a large block of text and find every instance[0] of
a certain word, in this case, instance[1] - and i\'d like to replace
every instance[2] number with another number, let\'s say [3].
string.replace doesn\'t quite cut it..
anyone able to help?
'
# 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