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

Solution with GREP /K from chapters and verses

Explorer ,
Feb 28, 2025 Feb 28, 2025

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

TOPICS
Type
440
Translate
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 ,
Feb 28, 2025 Feb 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.

Translate
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
Explorer ,
Mar 03, 2025 Mar 03, 2025
LATEST
 
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
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