Last active
December 24, 2015 22:19
-
-
Save analyticsPierce/6871644 to your computer and use it in GitHub Desktop.
Here is a helpful script for loading a csv file into an array so you can test regex.
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
#! /usr/bin/env ruby | |
require 'csv' | |
# step 1: import sproducts into an array | |
@file = "<your path and file>" | |
@sproducts = [] | |
CSV.foreach(@file, :headers => false) do |row| | |
@sproducts << row[0] | |
end | |
# create variable with regex function I want to test and print the matches | |
@sproducts.each { |line| | |
@matches = /^A.*/.match(line) | |
if @matches.nil? | |
else | |
puts @matches.to_s | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment