I am using the following code to delete spam messages that have specific words or phrases in them. I am having trouble finding what the limit is for the number of OR statements that I can have. I know I will eventually hit the ceiling. Can someone provide this information?
if (msg.getPlainBody().match(/car|truck|van|house|cat|dog|apple|orange|(you won)/gi) !== null) {
console.log('Msg Delete')
console.log(i)
Gmail.Users.Messages.remove('me', msg.getId())
continue;
}
In documentation there is no mention of limit for OR
statements, however, you should consider the string limit in Apps Script / JavaScript, since Apps Script is a JS platform I would say the limit is based on the JS documentation, I could not find official documentation for Apps Script but you can check this:
The language specification requires strings to have a maximum length of 253 - 1 elements, which is the upper limit for precise integers.
- In V8 (used by Chrome and Node), the maximum length is 229 - 24 (~1GiB). On 32-bit systems, the maximum length is 228 - 16 (~512MiB).
- In Firefox, the maximum length is 230 - 2 (~2GiB). Before Firefox 65, the maximum length was 228 - 1 (~512MiB).
- In Safari, the maximum length is 231 - 1 (~4GiB).
Also, it's recommended to follow best practices to keep a good performance of your scripts. By making your statement longer, the performance of the script may decrease and you could also encounter other limitations like script runtime.
References: