re = /(\d+)\s*-\s*(.*?)(?=;\s*\d|$)/m
str = '12 - ksjksu,nsusi,9018,1.00uy,9.0Vm,+/ - 20%(0.22suns); 891- 1o19jsksuisolslskosBN
205 - lksiosslsoujhs%ysus(0.33mismsn);31 - jsks,msnu
22 - 0204 - 2762.0uhsyuskis;14 - gnshj,msuis,lsolso2.2n; 67181 - iuwuwiwi
'
# 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