Skip to main content
Known Participant
January 16, 2017
Answered

How to combine shortest match with location, using GREP styles?

  • January 16, 2017
  • 1 reply
  • 3516 views

HI

This question is probably easy for those more experienced, but I'm having problem to make it work. I want to apply a GREP style to some text between parentheses, but not to all of them, only in a certain location (in my case, just when the parentheses are at the end of the paragraph).

I started with this, and it worked well, selecting all texts between parentheses:

Then, I thought that inserting a $ at the end of my expression, it would  select just the cases when the parentheses ocurred at the end of the paragraph. But it didn't work, and the selection came back to the "greedy" mode, as seen in the picture:

It worked in the second paragraph, in which we have just on occasion of parentheses, and they are at the end. But in the first paragraph, I want the GREP to be applied just  in (nsdvnsvk). How can I have the expected result?

Thanks,

This topic has been closed for replies.
Correct answer Peter Kahrel

Ah, yes, that one. I described it even in the PDF, p. 53:

\([^)]+\)$

\(      match an opening parenthesis

[^)]+   continue matching while not a closing parenthesis

\)       then match that parenthesis . . .

$       . . . at the end of the paragraph.

Peter

1 reply

Community Expert
January 16, 2017

\(.+?\)$

should do it.

P.

Known Participant
January 16, 2017

Hi Peter

Have you tested it? Because that's exactly what I did, but for me it doesn't work. It applies from the first opening parentheses in the paragraph to the last closing parentheses right before the end of the paragraph, instead of appplying just to the shortest match before the end of the paragraph…

Peter KahrelCommunity ExpertCorrect answer
Community Expert
January 16, 2017

Ah, yes, that one. I described it even in the PDF, p. 53:

\([^)]+\)$

\(      match an opening parenthesis

[^)]+   continue matching while not a closing parenthesis

\)       then match that parenthesis . . .

$       . . . at the end of the paragraph.

Peter