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

InDesign GREP expression for superscript references within brackets

New Here ,
Aug 07, 2018 Aug 07, 2018

Hello,

I have just discovered GREP and an using it to automatically make reference numbers Superscript.

The references come in a few ways:

[1]

[1,2]

[1-3], and finally, the format that I cant work out how to make GREP recognise:

[2,3,9-11]

Here is the expression I have written which works for the first three but not the last:

\[\d+\]|\[(\d+,\d+)*\]|\[\d+-\d\]|\[(\d,\d)*\d+-\d\]

What is the solution?

Thanks!

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

correct answers 1 Correct answer

Community Expert , Aug 07, 2018 Aug 07, 2018

Welcome to the World of Tomorrow GREP! It seems you have the right idea here, but you got lost in the codes at the end.

Remember that if you chain complicated expressions, you can always test them in isolation and see whether they work for the longer reference.

You went astray at the end of the first (\d,\d)* -- this repeats digit, comma, digit -- and then it expects yet another digit without a separator. Also, you forgot to add a "+" at the end, so it will match only a single digit number. You ca

...
Translate
Community Expert ,
Aug 07, 2018 Aug 07, 2018

Welcome to the World of Tomorrow GREP! It seems you have the right idea here, but you got lost in the codes at the end.

Remember that if you chain complicated expressions, you can always test them in isolation and see whether they work for the longer reference.

You went astray at the end of the first (\d,\d)* -- this repeats digit, comma, digit -- and then it expects yet another digit without a separator. Also, you forgot to add a "+" at the end, so it will match only a single digit number. You can see both if you change the text to "[2,31-1]", that will make your GREP work. Instead, try this:

\[(\d,)*\d+-\d+\]

You can chain even more expressions behind your current one to make it work for more complicated structures, but  I would propose a slightly shorter one, which incidentally also can manage mixed number ranges such as [1,3-5,7]:

\[\d[-,\d]*(?<=\d)\]

The trick here is that the match must start with [\d and then it can contain as many commas, dashes and digits as you want (including zero), and end with a square bracket that is preceded by a digit as well. (That last thing is me being fancy, by the way. It will prevent matching [1-]. A slightly easier to digest GREP that does not do such a check is the much shorter

\[\d[-,\d]*\]

which may already be enough if your text is properly edited.)

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
New Here ,
Aug 07, 2018 Aug 07, 2018
LATEST

Wow a reply in 2 minutes!

Thanks so much!

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