Skip to main content
deckarduk
Inspiring
October 27, 2022
Answered

InDesign JS grepFind whole word preference query...

  • October 27, 2022
  • 2 replies
  • 449 views

Hi there,

Please can someone help.

Is there a way to limit findGrep to finding whole words?

For example, if I'm searching for employee the word employees wouldn't be a match because of the 's'.

Thanks in advance.

This topic has been closed for replies.
Correct answer m1b

Another way, depending on your situation, is to include word boundary symbols \b in your grep. So

\bant\b

will find the word "ant", and won't find the "ant" in "rant" or "anthropic".

- Mark

2 replies

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
October 27, 2022

Another way, depending on your situation, is to include word boundary symbols \b in your grep. So

\bant\b

will find the word "ant", and won't find the "ant" in "rant" or "anthropic".

- Mark

deckarduk
deckardukAuthor
Inspiring
October 27, 2022

Hi Mark,

Thanks for the help and grep snippet. It worked a treat!

In my code I had to add escape characters to the \b so ended up with \\bemployee\\b, which worked.

Thanks again 🙂

 

rob day
Community Expert
Community Expert
October 27, 2022

Hi @deckarduk , I think you would have to do a find text to get at the whole word option. See the FindChangeTextOption.

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#FindChangeTextOption.html

deckarduk
deckardukAuthor
Inspiring
October 27, 2022

Hi Rob,

Thanks for the help. 

I've had a look at the link, the whileWord attribute looks like what I need.

I'm presuming with the FindChange option I'd have to find the word and then change it?