Mobile app version of vmapp.org
Login or Join
Jessie844

: Get the start and finish of text in a certain character style in Indesign GREP I've been fighting with InDesign GREP find/change quite a bit and couldn't find any way to get it to look at

@Jessie844

Posted in: #AdobeIndesign #Grep

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).

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Jessie844

1 Comments

Sorted by latest first Latest Oldest Best

 

@Kaufman565

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)

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme