re = /(?=(\d{2}\/\d{2}\/\d{4}))(?=([^\n]+\n)+[^\n]*BNA\sCNTRS[^=\n]*\n)([^\n]+\n)+/
str = '*044*05/02/2013*14:24*
*1234*1*(Iw(1*0, M-00, R-10011002100310041
A/C
OPERATION OK
*044*05/02/2013*14:24*
*1234*1*(Iw(1*0, M-00, R-10011002100310041
A/C
*044*05/02/2013*14:24*
*1234*1*(Iw(1*0, M-00, R-10011002100310041
A/C
OPERATION OK
[0r(1)2[000p[040qe1w3h162*054*05/04/2013*14:27*
*1234*1*(Iw(1*0, M-00, R-10011002100310041
A/C
*055*05/04/2013*14:27*
*1234*1*(Iw(1*0, M-00, R-10011002100310041
A/C
OPERATION OK
[020t*057*05/04/2013*14:27*
[05p
BNA CNTRS
LAST CLEARED : 00/00/00 00:00
COUNT
ENCASHED 141
[0r(1)2[000p[040qe1w3h162*065*05/05/2013*14:30*
*1234*1*(Iw(1*0, M-00, R-10011002100310041
A/C
OPERATION OK
*071*05/06/2013*14:31*
*1234*1*(Iw(1*1, M-00, R-10011002100310041
A/C
CUSTOMER CANCEL
[020t*076*05/06/2013*14:32*
[05p
BNA CNTRS
LAST CLEARED : 05/04/13 14:28
COUNT
ENCASHED 11'
# 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