Skip to main content
Inspiring
June 5, 2025
Answered

GREP Expression help

  • June 5, 2025
  • 3 replies
  • 773 views

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! 

Correct answer Catharine26941291c64a

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

 

3 replies

Inspiring
June 6, 2025

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)

Peter Kahrel
Community Expert
Community Expert
June 5, 2025

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

((; \K)|)\d+

No idea why that works though.

Inspiring
June 5, 2025

😄 as long as it does!! Thanks again.

 

Peter Spier
Community Expert
Community Expert
June 5, 2025

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.

Inspiring
June 5, 2025

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

Peter Kahrel
Community Expert
Community Expert
June 5, 2025

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