re = /^(?<nr_classe>(\d{4,}))([\x20\t\-]{1,}|[a-zA-Z]|$)/m
str = '250156304 - 6 ANO A INTEGRAL ANUA
250156445 - 7 ANO A INTEGRAL ANUA
250794211 - 2ª SERIE A INTEGRAL ANUA
250794484 - 2ª SERIE B INTEGRAL ANUA
250795069 - 3ª SERIE A INTEGRAL ANUA
250795291 - 3ª SERIE B INTEGRAL ANUA
250797255 - 6 ANO A INTEGRAL ANUA
250797644 - 7 ANO A INTEGRAL ANUA
250797800 - 7 ANO B INTEGRAL ANUA
250798147 - 8 ANO A INTEGRAL ANUA
250798493 - 9 ANO A INTEGRAL ANUA
250798725 - 9 ANO B INTEGRAL ANUA
251327540 - 8 ANO A TARDE ANUA
251327755 - 8 ANO B TARDE ANUA
251328951 - 7 ANO A TARDE ANUA
251329173 - 7 ANO B TARDE ANUA
251329173 -7 ANO B TARDE ANUA
251331013 - 6 ANO A TARDE ANUA
252381546 - 6074 - INFORMATICA PARA INTERNET - 1ª SERIE NT MANHA ANUA'
# 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