Created
September 22, 2017 23:14
-
-
Save blairanderson/a527c7205f40fbaf1fc84d153206e64d to your computer and use it in GitHub Desktop.
Amazon ASIN regex and Ruby for plucking asins from a textarea that is comma separated or newline separated
This file contains 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
class SomeController | |
def asin_params | |
# comma or semicolon, optionally surrounded by whitespace | |
# or | |
# two or more whitespace characters | |
# or | |
# any number of newline characters | |
String(params[:asins]) | |
.split(/ \s*[,;]\s* | \s{2,} | [\r\n]+/x) | |
.select { |item| item.length > 8 } | |
.map(&:upcase) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment