Created
May 13, 2020 10:21
-
-
Save pixeltrix/5139ad5fb1d996ca7e59b4244d96ff70 to your computer and use it in GitHub Desktop.
Match one of three number plate patterns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby anpr.rb | |
Result: RF10AKO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment