I can't get IndexOf to match correctly in GAS
I've tested out my regular expression here: https://regex101.com/r/0cK6xQ/1
As soon as there is a space inside the string, indexOf() will not match.
I even tried setting the regex as let contactRegExp = /(contact 1 Type)/i ; , which should be a direct match for the 2nd element in the sample array and it bombs out.
function setContactTypes(){
//Find all contact Type columns
let contactRegExp = /(contact [\d]* Type)/i ;
var headerIndexList = ['dummy1','contact 1 Type','dummy2','contact 2 Type'];
var hitArray = [];
var i = -1;
while ((i = headerIndexList.indexOf(contactRegExp,(i+1))) != -1){
hitArray.push(i);
}
}
hitArray should return [1,3]
I'm thinking it has something to do with an Array vs a string, but for the life of me can't figure it out.