if I use the following function within Google Sheets it doesn't return the value "not found". The logs tell me: "Execution cancelled".
This happens at the line:
var found = text.match(re);
If I change searchText to "abc" it works like a charme.
function example()
{
var text = "abc cba";
var searchText = "abcd";
var re = new RegExp(searchText,"g");
var found = text.match(re);
if (found === undefined) {
return "not found";
}
else {
return found;
}
}
Why is the script execution cancelled and how can I prevent this behavior without using the regex twice by using e.g. text.search(re) combined with if before the match() ?