Skip to main content
Inspiring
Feb 28, 2025 6:44 PM UTC
Question

Solution with GREP /K from chapters and verses

Hello everyone!
I have a text with Chapters and verses in each chapter.
I'm trying to put the Chapter number at the beginning of each verse using Find and Change with GREP expression: Search: (%)(\d+)(&)(?s)\w*.*?\K( \d+)(~S)
Change for: $5@$2$6

Each chapter number is between a hidden symbol % and &.

 

The problem is that sometimes Indesign puts the first chapter number instead of the closest previous one.
How can I make it take the nearest chapter number (%\d+&)?

Any idea?

 

I have removed \K from the GREP expression to see the selection without making changes. And I can see how it selects from the number Chapter1 to verse15 of Chapter 3. Instead of selecting from Chapter 3.

 

Thanks!!!

2 replies

James Gifford—NitroPress
Legend
Feb 28, 2025 6:55 PM UTC

You're going to have to provide a lot more detail about how your doc is structured and examples of before/after the GREP replacement for this to be an answerable question, I think. The nuts and bolts of the GREP expression are only a small part of it all.

Translate
SamLCAuthor
Inspiring
Mar 3, 2025 11:57 PM UTC
 
Thanks James for replying. I am attaching some screenshots of the document before and after applying the GREP expression. 
In the example everything seemed to be going well until reaching verse 5 of chapter 2. There it should say 5@2 instead of 5@1.
And then the same thing happens in verse 6 of chapter 5. It should be 6@5 but it appears 6@1. I don't know why this happens. Any ideas?
Translate