Skip to main content
Inspiring
August 25, 2022
Answered

Using GREP to remove superfluous characters in an index

  • August 25, 2022
  • 2 replies
  • 275 views

Hello InDeisgners,


A book I'm working on has an index that covers two volumes. The page references InDesign has generated look like this:

1.248, 1.312, 2.24, 2.39,

To make things easier to read, I've been trying to use GREP (and its 'Found' function) to add a semicolon between the references for the first and second volumes, so that entries look like this:

 

1.248, 1.312; 2.24, 2.39,

But the attempts I've made seem not to cover every option (I've tried it in three steps, to cover the possibility of there being up to three digits after the last '1.'). I mainly tried variations of finding (1.\d), (2.) and replacing it with $1; $2, but that also affects (for example) 2.104, 2.118, making it 2.104; 2.118 — which I don't want, and I don't know why it's happening...

If anyone has any experience with anything like this, I'd be keen to hear your thoughts.

 

On a related note, once I've sorted out the above, I'm keen not to have the volume numbers repeat, so ideally the whole entry would look like this:

 

1.248, 312; 2.24, 39

Again, if anyone has any suggestions for that, I'm keen to hear them (and to find out more about GREP and the Found elements; I can't quite work any of it out...).

This topic has been closed for replies.
Correct answer Mike Witherell

Now collapse the numbers:

Find

(?<=2\.\d+,\s)2\.

Replace

nothing

 

Then do similarly for the extra 1s for volume 1 entries

2 replies

Mike Witherell
Community Expert
Mike WitherellCommunity ExpertCorrect answer
Community Expert
August 25, 2022

Now collapse the numbers:

Find

(?<=2\.\d+,\s)2\.

Replace

nothing

 

Then do similarly for the extra 1s for volume 1 entries

Mike Witherell
M PAuthor
Inspiring
August 25, 2022

Wonderful! Thanks a lot.

Mike Witherell
Community Expert
Community Expert
August 25, 2022

A Positive Lookbehind will help:

Find

(?<=\s1\.\d+),

Replace

;

Mike Witherell
M PAuthor
Inspiring
August 25, 2022

Ah, thanks, that's great. I need to master looking behind and ahead in GREP!