re = /(?<!\d)(?!000|666|9)(order\W?number)?\W*(?<!x)\d{3}[ .=-]{0,10}(?!000)\d{3}[ .=-]{0,10}(?!000)\d{3}/im
str = 'x123456789
X123456789
x123-456-789
X123-456-789
123-456-789
ordernumber123-456-789
order number123-456789
order number 123456789
123-456789
123456789
ordernumber-123456787
ordernumber - 123456789
ordernumber #123456789
ordernumber !@#$%^&123456789
'
# 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