Skip to content

Instantly share code, notes, and snippets.

@pixeltrix
Created May 13, 2020 10:21
Show Gist options
  • Select an option

  • Save pixeltrix/5139ad5fb1d996ca7e59b4244d96ff70 to your computer and use it in GitHub Desktop.

Select an option

Save pixeltrix/5139ad5fb1d996ca7e59b4244d96ff70 to your computer and use it in GitHub Desktop.

Revisions

  1. pixeltrix created this gist May 13, 2020.
    20 changes: 20 additions & 0 deletions anpr.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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}"
    2 changes: 2 additions & 0 deletions output.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    $ ruby anpr.rb
    Result: RF10AKO