Grep help – positive look behind
Learn / Forums / General InDesign Topics / Grep help – positive look behind
Tagged: find and replace, GREP, positive look behind
- This topic has 4 replies, 2 voices, and was last updated 8 years, 9 months ago by Rivkah Lewis.
-
AuthorPosts
-
-
July 1, 2015 at 2:31 am #76351Rivkah LewisMember
I’m new at GREP, so bear with me…
I want to find any text preceded by the kind of enter that bumps things to the next text box and change the style.
This should find the first line of every new chapter in a story book I’m typesetting and apply the “title” style.I typed in
~P.+/r
and it found all of them, but also applied the style to that hard return on the previous page, which messed me up sometimes.
So I added a positive look behind:
(?<=~P).+/r
and now the find/change tells me it can’t find any matches.What have I done wrong?
-
July 1, 2015 at 10:20 am #76358Aaron TroiaParticipant
Rivkah,
Interesting, I hadn’t run into that before. It even does it when using Keep
\K
as well. Considering these are InDesign specific meta characters, I’m not sure why InDesign is having trouble with them when using a Lookbehind/Keep.Anyway, I don’t think you’re doing anything wrong, it’s a perfect use of the Lookbehind to me, but it might be easier to search for
~P
and then change them back to your body paragraph style.Aaron
-
July 1, 2015 at 10:25 am #76359Rivkah LewisMember
Thanks Aaron.
Nice at least to know I haven’t missed something fundamental :)I’m not familiar with \K – what is that?
-
July 1, 2015 at 10:44 am #76360Aaron TroiaParticipant
Keep (
\K
) is similar to a lookbehind, it consider’s everything before it as zero width but unlike a lookbehind it isnt greedy (ie you dont have to be explicit and you can use modifiers), so in the case of your GREP search (I couldnt get it to work but just using it as an example), actually let’s change the page breaks to tabs to simplify things:\t\K.+?\r
but what if you wanted to search for multiple tabs, in a lookbehind you would have to be explicit in how many tabs you were looking for, but with Keep you can use modifiers (such as +) to complete your search where as it would error out with a lookbehind:
\t+\K.+?\r
-
July 1, 2015 at 10:54 am #76361Rivkah LewisMember
Cool.
I’m going to try it.
Thanks for taking the time to explain.
-
-
AuthorPosts
- You must be logged in to reply to this topic.