Grep help – positive look behind

Learn / Forums / General InDesign Topics / Grep help – positive look behind

Viewing 4 reply threads
  • Author
    Posts
    • #76351
      Rivkah Lewis
      Member

      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?

    • #76358
      Aaron Troia
      Participant

      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

    • #76359
      Rivkah Lewis
      Member

      Thanks Aaron.
      Nice at least to know I haven’t missed something fundamental :)

      I’m not familiar with \K – what is that?

    • #76360
      Aaron Troia
      Participant

      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

    • #76361
      Rivkah Lewis
      Member

      Cool.
      I’m going to try it.
      Thanks for taking the time to explain.

Viewing 4 reply threads
  • You must be logged in to reply to this topic.
>