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

InDesign JS grepFind whole word preference query...

Contributor ,
Oct 27, 2022 Oct 27, 2022

Copy link to clipboard

Copied

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

Views

176

Translate

Translate

Report

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

Votes

Translate

Translate
Community Expert ,
Oct 27, 2022 Oct 27, 2022

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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 🙂

 

Votes

Translate

Translate

Report

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