re = /(\d{1,2}\.000) *\n* *(\d{1,4}\.\d{2})\n* *(\d{1,4}\.\d{2})\n* *(?:.*\n)?(\d{10}.*\n*[A-Z][A-Z])(*SKIP)(*F)|\D+|\d+/m
str = 'A11111111 22222-33333 SVC,IPHONE 15 PRO,DISPLAY
1.000 368.00 368.00
8524910000 CN
G111111111/22222222222/33333
5
A11111111 22222-33333 SVC,STUDIO BUDS
+,RIGHT,TRANSPRENT, 1.000 96.00 96.00
8517620000 CN
G111111111/22222222222/33333
2
A11111111 22222-33333 SVC,STUDIO BUDS
+,LEFT,TRANSPRENT,C 1.000 96.00 96.00
8517620000 CN
G111111111/22222222222/33333
2
A11111111 22222-33333 SVC,IPHONE 14 1.000 855.00
855.00
PRO,ROW,128G,PRP,CI/A
8517130000 CN
G111111111/22222222222/33333
7
A11111111 22222-33333 SVC,STUDIO BUDS
+,LEFT,BLACK/GOLD,C 1.000 96.00 96.00
8517620000 CN
G111111111/22222222222/33333
1'
subst = ''
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