Skip to content

Instantly share code, notes, and snippets.

@pixeltrix
Created May 13, 2020 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pixeltrix/5139ad5fb1d996ca7e59b4244d96ff70 to your computer and use it in GitHub Desktop.
Save pixeltrix/5139ad5fb1d996ca7e59b4244d96ff70 to your computer and use it in GitHub Desktop.
Match one of three number plate patterns
formats = [
"[A-Z]{2}[0-9]{2}[A-Z]{3}",
"[A-Z]{1}[0-9]{3}[A-Z]{3}",
"[A-Z]{3}[0-9]{3}[A-Z]{1}"
]
pattern = /\A#{formats.join("|")}\z/
candidates = %w[
RF10AK0
RF1OAK0
RF1OAKO
RF10AKO
]
match = candidates.detect(-> { "No Match" }) do |candidate|
candidate.match?(pattern)
end
puts "Result: #{match}"
$ ruby anpr.rb
Result: RF10AKO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment