Skip to main content
Inspiring
February 19, 2023
Answered

GREP expression in paragraph style

  • February 19, 2023
  • 2 replies
  • 1217 views

Hi,

I’m try to find a GREP expression to include in a paragraph style to capitalise (via style GREP) some words.

 

This is the pattern:
lastName1 Name1, y Name2 lastName2. Year.

 

I want to apply a character style to both lastName.

 

The first one is easy, but I have problems with the second one.

 

These are my tries:
- (?<=, y )\u\w+ //finds Name2
- (?<=y [^, ])\w+(?=\. (\d+)\.) //finds “astName2”
- (?<=y [^, ])\u\w+(?=\. (\d+)\.) //No results
- (?<=, y (\u\w+) )\u\w+ //No results
I’ve tried many but failed.

 

One thing to have in mind: lastName2 can have a hyphen in between (eg. Martinez-Ramirez).

 

Thank you all

This topic has been closed for replies.
Correct answer FRIdNGE

2 Grep Styles:

 

^[\w-]+

,(\h)y(?1)([\w-])+(?1)\K(?2)+

 

(^/)  The Jedi

2 replies

nicoshAuthor
Inspiring
February 19, 2023

Hi @Eugene Tyson thanks for your response, but it doesn't work for me. It finds any word before a dot but surprisingly no lastName2.

 

Before, to be brief, I haven't give information that now I believe important.

 

The text it's a bibliography so there is more information in each entry after the year, but it is variable, eg:

lastName1 Name1, y Name2 lastName2. Year. articleName, magazineName, pages.

 

Also there are entries with only one author mixed with two authors entries:

lastName1 Name1. Year. chapterName, bookName1, pages.

lastName1 Name1, y Name2 lastName2. Year. chapterName, bookName2, pages.

lastName1 Name1. Year. chapterName, bookName3, pages.

lastName3 Name3. Year. chapterName2, bookName4, pages.

 

I always can capitalise the first lastName of each entry via style GREP in paragraph style and use the find/change pannel for the second lastName with

\u\w+(?=\.\h\d+\.)

FRIdNGE
FRIdNGECorrect answer
Inspiring
February 19, 2023

2 Grep Styles:

 

^[\w-]+

,(\h)y(?1)([\w-])+(?1)\K(?2)+

 

(^/)  The Jedi

nicoshAuthor
Inspiring
February 20, 2023

@FRIdNGE 

GREAT!!

If you don't mind, can you translate to english the second expression? I'm a big fan of "Don't give them fish, teach them to fish"

Little Padawan

Braniac
February 19, 2023

(\h.+\h\K.+(?=\.\h))