The problem here is that by default GREP is GREEDY. When given the chance, the operators + and * try to grab as much as they can (still without violating the other constraints you put in the expression, of course).
In your case
perfectly matches the entire string, from the start all the way up to the end ... But you can force GREP to use the shortest possible match by adding a single "?" after the repeat-expression. This ought to work for you:
1 person found this helpful
I'm trying to italicise the contents of quotes within my document (am happy for the quotes to also be made italic, so no worries about being too clever trying to exclude them)
That's actually fairly easy -- apart from one tiny little issue
The usual way to delimit some string without including the delimiters is to use Lookbehind (?<=xx) before and Lookahead (?=yy) after the string. A typical example is
to find everything between parentheses, excluding the parentheses themselves (the open and close parentheses have to be escaped because they are 'special' inside the lookbehind/lookaheads). Similar to your previous query, it needs a shortest possible match to prevent grabbing an entire paragraph when possible.
So you would think all that's needed to exclude your quotes from the string is this expression:
Not ... exactly. This seems to match all strings with a double quote on its left and right, but InDesign does something unexpected:
It matches both each opening and closing (curly) quote with the single character ", so everything between the 'between the quotes' also matches! The only thing you can do to prevent this (not really the only thing, actually) is to explicitly check for a double opening and a double closing curly quote, like this:
Awesome, i learn something every day.
Who would have thought (apart from you experts) that is was just one question mark away from working.
I will definitely need to learn more about Grep, and I have just the project to use it with some vengance.
By the way, there is something I don't understand.
1) The GREP pattern:
is OK to grab each quoted text including quotes.
2) Using a lookbehind in the hope of retrieving the contents only:
this does not catch nothing! (CS4, CS5).
Can anybody explain this?
Marc, that's because the " character has been hijacked by the InDesign programmers -- as haphazard as some of their other good ideas
The " character is nothing special in GREP, but in InDesign it can match either the straight double quote, or both open and close curly quotes. In itself both halves of your expression seem to work:
positions the cursor right after either an open or close curly quote, and this one works as expected, excluding both open and close curly quotes:
So it's only the combination that fails! Extremely irritating is that the next logical thing to try
also does not work -- but suddenly it comes alive when you copy a double quote from your InDesign document, and this finally works:
(The first dbl quote is a curly one.) (30 seconds later:) A random thing I just tried also seems to work -- and I have no clue why it does: