Created
May 13, 2020 10:21
-
-
Save pixeltrix/5139ad5fb1d996ca7e59b4244d96ff70 to your computer and use it in GitHub Desktop.
Revisions
-
pixeltrix created this gist
May 13, 2020 .There are no files selected for viewing
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 charactersOriginal 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}" 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ $ ruby anpr.rb Result: RF10AKO