I have an HTML user form select and input fields whose input I need to search within a string in google sheets.
Here is what the cell looks like.
I have the following function that does a great job of searching through cells and returning values I don't want in an array that I can use with .setHiddenValues() when filtering.
function getHiddenValueArray(colValueArr,visibleValueArr){
//colValueArr = SpreadsheetApp.getActive().getSheetByName('Monthly_Detail').getRange(2,64,359,1).getValues();
//visibleValueArr = ['last1']; //In this case user will only input 1 name
//strictLevel = 'lenient'
//will find a match within a cell
var flatUniqArr = colValueArr.map(function(e){return e[0].toString();})
.filter(function(e,i,a){
return (a.indexOf(e) == i && !(visibleValueArr.some(function(f){
return e.search(new RegExp(f,'i'))+1;
})));
});
Logger.log(colValueArr);
Logger.log(flatUniqArr);
return flatUniqArr;
}
I believe the reason why this function does not work is because of the 3 line breaks and the one trailing line break in the cell's data.
Here are my Questions:
- I'm still a beginner and RegEx is still very foreign to me. Is there a way to use regex to bypass the leading and trailing line breaks so that the rest of the function will work? I've deleted some manually and filtering works on those cells.
- How can I have it search for Member Type: first or Member Type: last?
I'm Ok with having a third if within this if needed with an extra variable for Member Type.
Clarifications:
- I'm aware that I could manually or programatically delete these new lines, but this data is refreshed daily. I'd like to see the string search function is possible first.
Notes from comments:
- Logs show that the function is correctly excluding those that match what I eventually want to filter the column on. This leads me to believe that the issue lies with having
.setHiddenValueswith newlines or google sheets cannot filter on cells that have newlines. - To test the above I deleted newlines from
flatUniqArrusingflatUniqArr[i]= flatUniqArr[i].replace(/(\r\n|\n|\r)/gm,"");in a loop. Logs show this eliminated newlines. However, still no go. That narrows it down to google sheets not being able to filter on cells that have newlines.


'string|with|breaks|||'.split('|').filter(item => !!item)style. - wizebin\n+means look for at least one newline followed by any quantity more,\n*means 0 or more newlines. - wizebinflatUniqArrproperly. I'm thinking the issue is with either.setHiddenValuesand strings with newlines or the actual filtering on the column in google sheet. - DanCue