I'm using a Google Script to extract values from a column that match my regex, but I can't seem to get my regex variable to work with my if statement. When I set the variable to a string, I have no problem with running my function and getting a response back, but it isn't working with the regex and I'm trying to figure out the issue:
Here is my script:
function extractBranded() {
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();
for (var i = 0; i < data.length; i++) {
var keywords = /ipad dns|dns system/;
if (data[i][0] == keywords) {
Logger.log(data[i][0]);
} else {
}
}
Google Sheets Data (Queries = Column and Row A1):
Queries
dns system
dns systems
ipad dns
ipad dns system
business 101
ipad dns register
dns
In theory this should pick up on four of the seven values in my sheet.
I also tried calling a constructor function with new RegExp(), but this did not work. Any thoughts?
if (data[i][0].match(keywords)) {, I obtained 5 results:dns system,dns systems,ipad dns,ipad dns system,ipad dns register- is it what you are looking for? You forgot to call.match(). Ortest():if (keywords.test(data[i][0])) {