Take the 2-minute tour ×
Graphic Design Stack Exchange is a question and answer site for professional graphic designers and non-designers trying to do their own graphic design. It's 100% free, no registration required.

I've been fighting with InDesign GREP find/change quite a bit and couldn't find any way to get it to look at the start and the end of a character style. This is necessary if, for example, you want to grab only whole chunks of a character style and only if they don't contain something.

For example, you might have text like...

Lorem ipsum dolor sit2-4 amet, consectetur5 adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud2,3 exercitation ullamco6 laboris nisi ut aliquip ex ea commodo consequat.

...and you want to make GREP rules that strictly start only from the start of each snippet or span of the character style applying the superscript, and strictly end only at the end of the character style applying the superscript.

(for example, so you can find whole snippets that don't contain punctuation like "-" or ",", without finding sub-snippets that aren't punctuation such as the 2 in "2,3")

Using ^ and $ (beginning and end of paragraph/line) with a character style specified in Find/Change gives weird results and then crashes. Using word boundaries \b and the mysterious "opposite of a word boundary" \B also gave strange results (jumping the cursor to the right place once, then not selecting anything and not finding any more locations).

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

I figured something out based on the fact that, with a character style selected, InDesign GREP doesn't register the existence of any characters not of that character style.

(?<!.).+(?!.) - this selects the whole of a snippet of a character style, strictly starting at the start and strictly finishing at the finish.

You can use this to include negation (e.g. (?<!.)[^-]+(?!.) finds only whole chunks of a character style that don't contain "-", (?<!.)[^Gor blimey]+(?!.) finds only whole chunks of a character style that don't contain "Gor blimey").

  • Start with (?<!.) to specify that the selection must begin at the start of this chunk of the selected character style
    • It's a "negative lookbehind" on . meaning, only select from here if the character before this selection is not [any character] (i.e. if there's nothing of the selected character style before this selection)
  • End with (?!.) to specify that the selection must end at the end of this chunk of the selected character style
    • It's a "negative lookahead" on . meaning, only select to here if the character after this selection is not [any character] (i.e. if there's nothing of the selected character style after this selection)
share|improve this answer
    
I dug in and played with a test document for a while, and reached the same conclusion you did. This would be a great way to layer character styles if it also worked in GREP Styles, but unfortunately it still won't as of ID CC because the starting point has to be the Style selector. –  Alan Gilbertson Jun 28 '13 at 23:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.