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).
Finer:
(?s)^.+?\K[~s~S\H]+(?=\.(?!\d))
(^/)
Copy link to clipboard
Copied
Copy link to clipboard
Copied
That works perfectly!
Would you mind breaking it down so I can understand it?
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
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.
As you'll see, the 2nd paragraph should also have "colony" in the case, in bold as well.
Any thoughts?
Copy link to clipboard
Copied
(?s)^.+?\K\H+(?=\.(?!\d))
(^/) The Jedi
Copy link to clipboard
Copied
Finer:
(?s)^.+?\K[~s~S\H]+(?=\.(?!\d))
(^/)
Copy link to clipboard
Copied
Thank you, this works!
Copy link to clipboard
Copied
Depends on the number of paragraphs - it may slow InDesign significantly - if you set it in ParaStyle.