Skip to main content
Inspiring
June 6, 2025
Answered

GREP expression - reference list

  • June 6, 2025
  • 2 replies
  • 413 views

Hi. (This may be a duplicate post, but I couldn't find my first attempt, so here we go again...)
More GREP ineptitude from me. I'm afraid. I need to be able to make just the first number within the parentheses bold, but not any others. In this sample, I have the solution:

(1) Surname Initial et al. Journal 2000;10:2XX–2XX; (2) Surname Initial et al. Journal 2000;10:2XX–2XX;
(3) Surname Initial et al. Journal 2000;10:2XX–2XX; (4) Surname Initial et al. Journal 2000;10:2XX–2XX;
(5) Surname Initial et al. Journal 2000;10:2XX–2XX; (6) Surname Initial et al. Journal 2000;10:2XX–2XX;
(7) Surname Initial et al. Journal 2000;10:2XX–2XX.

 

(?<=\()\d+.*?(?=\)) works well, but there are times when there is another number buried within each reference that can be in brackets, like this:

(1) Surname Initial et al. Journal 2000;10(23):2XX–2XX; (2) Surname Initial et al. Journal 2000;10(23):2XX–2XX;

What do I need to add to my GREP to only choose the first parenthethical number? I thought a second GREPwould work, but, alas, no:

(?<=; )\d+

Any suggestions? They are all separated by a semicolon/space or semicolon/soft return, (which I guess may require yet another GREP! <sigh>) if that helps These are set scientific styles and unfortunately cannot be altered to make my life easier...

Correct answer Peter Spier

This is pretty similar to yesterday's question, and again I can only make it work here using two expressions:

(?<=^\()\d+(?=\)) for the first one at the start of a your list and (?<=; \()\d+(?=\)) to find the rest. This presumes your lines are separated by hard returns. If you have lines that are ending in a semicolon followed by a soft return, using (?<=;\s\()\d+(?=\)) will get the ones after the soft retuns (and hard returns as well) along with the ones mid-line.

Your trick with the parentheses around the ^ did not work for me to combine the two...

2 replies

Peter Spier
Community Expert
Peter SpierCommunity ExpertCorrect answer
Community Expert
June 6, 2025

This is pretty similar to yesterday's question, and again I can only make it work here using two expressions:

(?<=^\()\d+(?=\)) for the first one at the start of a your list and (?<=; \()\d+(?=\)) to find the rest. This presumes your lines are separated by hard returns. If you have lines that are ending in a semicolon followed by a soft return, using (?<=;\s\()\d+(?=\)) will get the ones after the soft retuns (and hard returns as well) along with the ones mid-line.

Your trick with the parentheses around the ^ did not work for me to combine the two...

nikunj.m
Legend
June 6, 2025

Hi, I'll merge this post with the conversation you started yesterday. If you wish to look at the posts you've done, you can click on the Profile Icon on the top right, and select View Community Profile. 


Thanks,
Nikunj

Inspiring
June 6, 2025

thank you, but this is actually a related but different query. The original post was to do with endnotes. This question is about bibliography, which is completely different. Please can  you take it back to a separate question? otherwise I'll not get an answer

 

nikunj.m
Legend
June 6, 2025

Done, I've made it a dedicated post again. Sorry about the confusion! 

For what you're looking for, I found this (?<=^|\;\s?)\(\d+\)

Can you check if that helps? 


Thanks,
Nikunj