Skip to main content
Participant
April 4, 2024
Answered

GREP help with index for name/surname grammatical case system

  • April 4, 2024
  • 3 replies
  • 423 views

Good day. I am trying to make an Index list - surname/name/page. However I cannot add one single name with "add all" function.

In my Lithuanian language, there is a grammatical case system.

NAME SURNAME :

Jonas Jonaitis 

Jono Jonaičio

Jonui Jonaičiui

I would need to highlight every name grammatical case and add it to the index, but the name is the same, only the case is not. And I would have several entries of the same name under "X" letter.

In this example, I would need the grep to find all grammatical cases of Jon* Jonai* (name/surname) and make it the default name case - Jonas Jonaitis. Then also swap to surname/name style.

The final result should look like:

J

Jonaitis Jonas

I don't know how to write this 😞

Do you think this is too much? Should I just highlight every name with different case, and then just edit generated index? I would just need to figure out how to swap name/surname to surname/name.

Thank you, V.

This topic has been closed for replies.
Correct answer Peter Kahrel

If searching for all instances of words that start with Jon or Jonai is certain only to return names and nothing else, you can look for 

 

Jon\l+ Jonai\l+

 

(\l stands for lower-case letter, + means one or more.)

 

If that's too wide you can specify the case endings:

 

Jon(as|o|ui) Jonai(tis|čio|čiui)

 

To mark up Jonas in your document, you can use this script:

 

var index = app.documents[0].indexes[0];
if (!index.isValid) {
  index = app.documents[0].indexes.add();
}

app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = 'Jon\\l+ Jonai\\l+';
found = app.documents[0].findGrep();
if (found.length > 0) {
  topic = index.topics.add ('Jonaitis, Jonas');
  for (i = found.length-1; i >= 0; i--) {
    topic.pageReferences.add (found[i].insertionPoints[0]);
  }
}

 

(Edit: Eugene posted while I was typing away)

 

3 replies

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
April 4, 2024

If searching for all instances of words that start with Jon or Jonai is certain only to return names and nothing else, you can look for 

 

Jon\l+ Jonai\l+

 

(\l stands for lower-case letter, + means one or more.)

 

If that's too wide you can specify the case endings:

 

Jon(as|o|ui) Jonai(tis|čio|čiui)

 

To mark up Jonas in your document, you can use this script:

 

var index = app.documents[0].indexes[0];
if (!index.isValid) {
  index = app.documents[0].indexes.add();
}

app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = 'Jon\\l+ Jonai\\l+';
found = app.documents[0].findGrep();
if (found.length > 0) {
  topic = index.topics.add ('Jonaitis, Jonas');
  for (i = found.length-1; i >= 0; i--) {
    topic.pageReferences.add (found[i].insertionPoints[0]);
  }
}

 

(Edit: Eugene posted while I was typing away)

 

Community Expert
April 4, 2024

That makes a lot more sense 

Community Expert
April 4, 2024

Another way I've done it before GREP days 

Find the space 

replace it with a tab

Select the text and convert it to a table
Then swap the columns
Then convert the table back to text

 

 

You don't technically need to change the space toa. tab - you can just ty convert to a table and use the space character to invoke the columns and rows etc

Community Expert
April 4, 2024

If you're only looking to swap the first and last name it's pretty simple
Given names are start of sentences


Find

^(.+?) (.+)
Change to
$2 $1

If it's more complicated than that let us know.