Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

InDesign JS grepFind whole word preference query...

Contributor ,
Oct 27, 2022 Oct 27, 2022

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.

TOPICS
Scripting
425
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 27, 2022 Oct 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

Translate
Community Expert ,
Oct 27, 2022 Oct 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 27, 2022 Oct 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 27, 2022 Oct 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 27, 2022 Oct 27, 2022
LATEST

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 🙂

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines