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.
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.
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.
Copy link to clipboard
Copied