Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Indesign GREP Javascript

Community Beginner ,
Jun 11, 2021 Jun 11, 2021

Copy link to clipboard

Copied

I have a list of given names that include first names and the middle names. I want to remove all of the middle names leaving only the first name.

Here is an example of the names I have in the list. I have bolded the part of the name that I want to keep. The query should only select an remove the non-bolded names. As you can see some people have a middle name and others have none. Some first names are hyphenated and some middle names have 2 words.

Peta-Louise Mary

Felicity-Ann

Neale Francis

Stephen Misha

Erika Elizabeth

Anna Oi Chan

Susan

 

My first query worked on most names, except for instances where a persons first name had a hyphen in it (i.e. Peta-Louise Mary). 

I have a GREP query that is working in Indesign (2018) but when I put the same query into my Javascript version, it isn't working.

My GREP query that works in Indesign is:

(?<!^)(?<=\s)\b.+\b(?=(\s+)?$)

 

My Javascript search line is as follows:

 

app.findGrepPreferences.findWhat = "(?<!^)(?<!\\s)\\b.+\\b(?=(\\s+)?$)";

 

 Can anyone see where I am going worng with the Javascript version or can suggest another way of doing it? I have a suspicion that the problem is the two negative lookbehinds at the start.  I tried combining them with (?<![^,\\s]) but that didn't work.

TOPICS
Import and export, Scripting

Views

123

Likes

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

Adobe Community Professional , Jun 11, 2021 Jun 11, 2021
If you look carefully, your JS version is not the same as your ID version. The second lookbehind is different. But why don't you simply remove everything after the first space character? P.

Likes

Translate

Translate
Adobe Community Professional ,
Jun 11, 2021 Jun 11, 2021

Copy link to clipboard

Copied

If you look carefully, your JS version is not the same as your ID version. The second lookbehind is different.

 

But why don't you simply remove everything after the first space character?

 

P.

Likes

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 Beginner ,
Jun 11, 2021 Jun 11, 2021

Copy link to clipboard

Copied

LATEST

Thanks @Peter Kahrel You're right! I don't know how I missed such an obvious mistake.

 

Thanks

Likes

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