Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

GREP Expression help

Explorer ,
Jun 05, 2025 Jun 05, 2025

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! 

TOPICS
How to , Print , Type
268
Translate
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 Expert ,
Jun 05, 2025 Jun 05, 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.

Translate
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
Explorer ,
Jun 05, 2025 Jun 05, 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

Translate
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 Expert ,
Jun 05, 2025 Jun 05, 2025

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

Translate
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 Expert ,
Jun 05, 2025 Jun 05, 2025

OOOPS.

Thanks, Peter

Translate
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 Expert ,
Jun 05, 2025 Jun 05, 2025

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

((; \K)|)\d+

No idea why that works though.

Translate
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
Explorer ,
Jun 05, 2025 Jun 05, 2025

😄 as long as it does!! Thanks again.

 

Translate
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
Explorer ,
Jun 05, 2025 Jun 05, 2025

Still need the two-style solution as this single one also catches the number 12 in the Spanish hospital title

Translate
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 Expert ,
Jun 05, 2025 Jun 05, 2025

In that case use

((; \K)|)\d+(?=\u)

which stipulates that the number should be followed by an upper-case letter.

Translate
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 Expert ,
Jun 05, 2025 Jun 05, 2025

@Peter Kahrel any idea why ^\d+|(?<=; )\d+ doesn't work? For me it only captures the first number after the ; and nothing else.

Translate
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
Explorer ,
Jun 05, 2025 Jun 05, 2025

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

 

Translate
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 Expert ,
Jun 05, 2025 Jun 05, 2025

OK, That's pretty  strange to my way of thinking. It doesn't work if you put parentheses around the whole ^\d+

Translate
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 Expert ,
Jun 05, 2025 Jun 05, 2025

I've no idea. I tried that one, in fact. So I don't know why this one doesn't work, and I don't know why the one I hit on accidentally does. 

Translate
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
Explorer ,
Jun 06, 2025 Jun 06, 2025
LATEST

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
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