Skip to content

Instantly share code, notes, and snippets.

@blairanderson
Created September 22, 2017 23:14
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 blairanderson/a527c7205f40fbaf1fc84d153206e64d to your computer and use it in GitHub Desktop.
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
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