re = /F Blocks:[\t ]+(0x)?([0-9a-f]+)[ ]+(0x)?([0-9a-f]+)[ ]+(0x)?([0-9a-f]+)/m
str = 'Entry : 12300000
F Blocks: 00000020 0x00000000 0x000a1b00
S Blocks: 0x00100000 0x0000001c 0x00000150'
subst = '0x\\2 0x\\4 0x\\6'
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