Skip to main content
Inspiring
Jun 5, 2025 9:02 AM UTC
Answered

GREP Expression help

Sorry to bother, but I'm still struggling with GREP! I need an expression that superscripts the numbers at the start of a string of references - for example:

 

1Princess Margaret Hospital, Toronto, ON, Canada; 2University of Manitoba, Winnipeg, MB, Canada; 3London School of Economics, London, UK; 4Hospital Universitario 12 de Octubre Madrid, Spain.

 

The references need to remain a single line,  each reference separated by a semicolon, and the digits can typically include up to 2 characters. As in my example, the names can include digits at times, so those would have to be excluded from superscripting. Help! 

Catharine26941291c64aCorrect answer
Inspiring
Jun 5, 2025 4:37 PM UTC

I had to put parentheses around the first caret - that worked for me, anyway

 

13 replies

Inspiring
Jun 6, 2025 8:36 PM UTC

A grep style in a paragraph style applying a character style with superscript works also.

\d+(?=\u)

OR

\d{1,2}(?=\u)

OR (if there are lowercase letters starting the name)

\d+(?=\u|\l)

Translate
Peter Kahrel
Community Expert
Community Expert
Jun 5, 2025 2:03 PM UTC

A typo on my part caused a single expression to work:

((; \K)|)\d+

No idea why that works though.

Translate
Inspiring
Jun 5, 2025 2:07 PM UTC

😄 as long as it does!! Thanks again.

 

Translate
Peter Spier
Community Expert
Community Expert
Jun 5, 2025 11:54 AM UTC

I can make this work with two expressions aaplied as GREP styles separately, but not as a single expression that catches all cases.

^/d+ catches the initial digit, and (?<=; )\d+ catches the ones after.

Translate
Inspiring
Jun 5, 2025 1:17 PM UTC

Hi. 
^/d+ isn't catching the first digit for me, but if I put parenthases around the caret, it works - not sure if that will create other issues, but if works for now! Thanks Peter

Translate
Peter Kahrel
Community Expert
Community Expert
Jun 5, 2025 1:58 PM UTC

It's a typo: the slash should be a backslash: ^\d+

Translate