dnmh
dnmh

Reputation: 2135

Office.js escape special characters in search

I'm attempting to do a relatively straight-forward search (not through the UI, but programmatically) with wildcards but I'm having issues with special characters.

Inside the document, I have some data like this: {name:2003}, {otherName:2005} and maybe something like {name:2003b} (those are citekeys). I want to search them like this:

context.document.body.search('{*}', {matchWildCards: true});

But the issue is that { and } are special characters as described here: https://dev.office.com/reference/add-ins/word/searchoptions - there's even a part at the bottom about escaping the special characters programmatically, but I still don't get it. It says "...to escape it programmatically, put it between '' characters...". I've tried a couple of variations, all without success, I get an error each time when I try the search.

What is the correct way to escape these characters for my case?

Upvotes: 1

Views: 215

Answers (1)

Rick Kirkham
Rick Kirkham

Reputation: 9784

That's a typo in article. To escape a character, you put it between square brackets; the '[' and ']' characters. So to escape "{", you use [{].

Upvotes: 2

Related Questions