re = /^(02|03|04|06|08|09|072|074|076|077|078|079|050|051|052|053|054|055|056|058|059)((?:(?![1,0]{1}))\d{7})$/m
str = 'Valid:
022345677
032345677
042345677
062345677
082345677
092345677
0722345677
022345677
0742345677
0762345677
0742345677
0762345677
0772345677
0782345677
0792345677
0502345677
0512345677
0522345677
0532345677
0542345677
0552345677
0562345677
0582345677
0592345677
NotValid :
021345677
030345677
142345677
362345677
282345677
492345677
5722345677
622345677
7742345677
8762345677
9742345677
'
# 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