Skip to main content
Inspiring
February 28, 2025
Question

Solution with GREP /K from chapters and verses

  • February 28, 2025
  • 1 reply
  • 817 views

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!!!

1 reply

James Gifford—NitroPress
Legend
February 28, 2025

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.

SamLCAuthor
Inspiring
March 3, 2025
 
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?