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

GREP help with index for name/surname grammatical case system

New Here ,
Apr 04, 2024 Apr 04, 2024

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

264

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Apr 04, 2024 Apr 04, 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 =
...

Votes

Translate

Translate
Community Expert ,
Apr 04, 2024 Apr 04, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 ,
Apr 04, 2024 Apr 04, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Apr 04, 2024 Apr 04, 2024

Copy link to clipboard

Copied

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)

 

Votes

Translate

Translate

Report

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 ,
Apr 04, 2024 Apr 04, 2024

Copy link to clipboard

Copied

That makes a lot more sense 

Votes

Translate

Translate

Report

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
New Here ,
Apr 15, 2024 Apr 15, 2024

Copy link to clipboard

Copied

LATEST

Thank you very much, this is exactly what I was looking for!

Have a lovely day,

V.

Votes

Translate

Translate

Report

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