re = /(?<=SUBH2002078568)[\s\S]+?(?=SUBF2002078568)/m
str = 'HMT940040324
SUBH2002078568
2002078568{1:F01BANK MBI}{2:I940MAP}{4:
2002078568:20:20210420182417
2002078568:25:2002078568
2002078568:28C:00075
2002078568:60F:D210420IDR0,
2002078568:62F:D210420IDR0,
2002078568-}
SUBF2002078568
SUBH2003001298
2003001298{1:F01BANK MBI}{2:I940MAP}{4:
2003001298:20:20210420182417
2003001298:25:2003001298
2003001298:28C:00075
2003001298:60F:C210420IDR111520964,38
2003001298:62F:C210420IDR111520964,38
2003001298-}
SUBF2003001298
SUBH2002078568 // *Added this account from the top*
2002078568{1:F01BANK MBI}{2:I940MAP}{4:
2002078568:20:20210420182417
2002078568:25:2002078568
2002078568:28C:00075
2002078568:60F:D210420IDR0,
2002078568:62F:D210420IDR0,
2002078568-}
SUBF2002078568- // End
FMT9400000004'
# 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