Copy link to clipboard
Copied
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!
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
...Copy link to clipboard
Copied
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.)
Copy link to clipboard
Copied
Wow a reply in 2 minutes!
Thanks so much!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now