re = /^(?=.*\d)[_0-9]{2}-[_0-9]{3}$/m
str = '11-111
_1-111
1_-111
11-__1
11-_1_
11-1__
11-11_
11-1_1
11-_11
11-111
1_-1_1
__-__1
1_-___
__-_1_
_1-___
11-___
__-1__
'
# 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