I am importing data from an excel file and am trying to locate certain information from their relevant columns by using RegEx to locate columns that have the data that I am looking for. However, the regex is imperfect because sometimes the expressions are found in more than one column. So to account for this basically I want to make some sort of internal counter that will count the number of times that a column has one of the Regular Expressions that I have defined in the set. An example for this is happening can be found below.
columnsWithDescription()
{
var refDesRegex = [/resistor/i,/capacitor/i,/res/i,/cap/i]
var refDesColumnNumber = new Set();
for (var expression of refDesRegex)
{
for (const row of this.data)
{
for (var cell = 0; cell<row.length; cell++)
{
if (expression.test(row[cell]))
{
refDesColumnNumber.add(cell)
}
}
}
}
data
is the excel sheet that has been imported. It is an array of arrays where each array is a row of the excel sheet.
I have experimented with using the forEach method on the resulting Set but this results an overall true count and doesn't isolate the results from each column number. I want to run the test on each value of the set and see how many times the value in the column that matches the cell index returns true and then isolate that row so I can push it into an array later.