Search code examples
google-apps-scriptgoogle-slides-apigoogle-slides

Escaping meta chars in slides apps script not working


I want to match 212*235 as plain text in Slides service Text Range. Hence I used

var trs = text.find('212*234'); var trs = text.find(/212*234/);

also tried with

var re = new RegExp("212*234", "gi"); var trs = text.find(re);

but none of them worked.

https://developers.google.com/apps-script/reference/slides/text-range#findpattern

Is this might be a bug or intentional?


Solution

  • You want two backslashes before the *, as in:

    var s = SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0];
    Logger.log(s.getText().find('212\\*235')[0].asString());