I am trying to pass in simple regex strings like
findText("/a/");
or
findText(/a/);
but it does not find anything. If I pass in only the text that works like this
findText("a");
How to pass regex strings in there?
It's not super clear in the documentation of findText, but the documentation for replaceText is more clear:
The search pattern is passed as a string, not a JavaScript regular expression object.
The example shown in the documentation of replaceText shows that your 3rd example is the correct one (where the search for a is shown as just the string, "a".
body.replaceText("^.*Apps ?Script.*$", "Apps Script");
Obviously, String.search() will work here as well, but if you're looking to manipulate the attributes of the text, rather than just the string contents, using the built-in javascript function might leave you hanging.
If 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