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

GREP expression help. Find the last word in only the first sentence of a paragraph

New Here ,
May 25, 2023 May 25, 2023

Copy link to clipboard

Copied

Firstly, thank you in advance for reading and helping.

 

I need to find a GREP expression that will style in bold, only the last word in the first sentance of a paragraph, regardless of what that word is.

 

I can find the first word in the first sentence, but not the last:

(?=^((\w+)\s )+\w+\.)\w+

 

So in the below example, only "colony" should be put into bold.

 

Ants live together in a colony. The average colony has over 100,000 ants in it. That’s a lot of ants!

 

Any help provided will be greatly appreciated. (This expression needs to work in a paragraph style).

TOPICS
Scripting

Views

458

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

Guide , May 25, 2023 May 25, 2023

Finer:

 

(?s)^.+?\K[~s~S\H]+(?=\.(?!\d))

 

Capture d’écran 2023-05-25 à 20.29.21.png

 

(^/)

Votes

Translate

Translate
Community Expert ,
May 25, 2023 May 25, 2023

Copy link to clipboard

Copied

Hi @SamB5055,

Try the following

^..*?\K\w+(?<!\d)\.(?!\d)

-Manan

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
New Here ,
May 25, 2023 May 25, 2023

Copy link to clipboard

Copied

That works perfectly!

 

Would you mind breaking it down so I can understand 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 ,
May 25, 2023 May 25, 2023

Copy link to clipboard

Copied

Sure. So the ^ means to start the search from the start of the input, this will ensure that we hit the first sentence only. After that we keep on consuming characters but not include it in our final result which is done by \K. After that we search for a word with \w+ which is to be followed by a .(sentence end marker), provided . is not preceded/followed by a number by using negative lookbehind and negative lookahead, this avoids picking a decimal marker within a number as the line end character.

Hope this helps

-Manan

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
New Here ,
May 25, 2023 May 25, 2023

Copy link to clipboard

Copied

So I've done a bit more testing and whilst initially I thought this worked perfectly, it doesn't seem to be the case.

 

SamB5055_0-1685028789754.png

As you'll see, the 2nd paragraph should also have "colony" in the case, in bold as well.

Any thoughts?

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
Guide ,
May 25, 2023 May 25, 2023

Copy link to clipboard

Copied

(?s)^.+?\K\H+(?=\.(?!\d))

 

(^/)  The Jedi

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
Guide ,
May 25, 2023 May 25, 2023

Copy link to clipboard

Copied

Finer:

 

(?s)^.+?\K[~s~S\H]+(?=\.(?!\d))

 

Capture d’écran 2023-05-25 à 20.29.21.png

 

(^/)

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
New Here ,
May 26, 2023 May 26, 2023

Copy link to clipboard

Copied

LATEST

Thank you, this works!

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 ,
May 25, 2023 May 25, 2023

Copy link to clipboard

Copied

Depends on the number of paragraphs - it may slow InDesign significantly - if you set it in ParaStyle. 

 

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