I tried indexOf(), findText() and other few methods for finding a string pattern in a text in google app script. None of the above method works.
var str="task is completed";
I'm getting this string from google spreadsheet.
I just want to find whether the above string contains a string "task" .
You need to check if the str
is present:
if (str) {
if (str.indexOf('task') > -1) {
// Present
}
}
Alternatively, you can use test
and regex
:
/task/.test("task is completed");
/task/.test(str);
/task/
: Regex to match the 'task'test
: Test the string against regex and return booleanIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With