Home > Net >  Google Apps script "like" in if statement? Wildcards?
Google Apps script "like" in if statement? Wildcards?

Time:11-26

I have some scripting to format cell color. I would like to use LIKE to search inside the string (cell value). I am having a hard time finding something that works. I am very much new to Google Apps Script\Java.

Basically I want an if statement for a cell value, if it contains the word "extra" with anything before or after it. So it would match for 1extra and extra1, with any number of characters before or after.

Thanks for any help!

CodePudding user response:

If you just want to check if a certain string is present, then you can use sample

Output:

output

Note:

  • .* surrounding "extra" means that any number of any character (it will match any string, be it very long, or none at all)
  • modifier i after /.*extra.*/ means it will match regardless of the case (case insensitive - e.g. will match even if we want is "extra" and the one in the string is "Extra"). If you want to only match the exact string "extra", remove the i.

Reference:

  • Related