2 Replies Latest reply on Feb 11, 2016 3:47 PM by soundman1963

    InDesign CC Grep Find/Change to replace space character with paragraph (pilcrow)

    soundman1963 Level 1

      Hello InDesigners,

       

      I'm in the process of cleaning up a 99 page document. Throughout the file there are chapter titles, in uppercase, followed by a space character, which is then followed with more uppercase text.This always occurs at the beginning of a paragraph.

      I'm trying to target the space character that appears right after the chapter number and swap it out for a (pilcrow).

       

      For example:


      CHAPTER 22 SUNDAY BELOW GROUND

       

      I want to have Grep change this to read:

       

      CHAPTER 22

      SUNDAY BELOW GROUND

       

      I know that to make this work, I need to use Positive Look Behind and Positive Look Ahead, initially, I first just tried to isolate CHAPTER 22 using the following:

      ^\u{2,}\s\d+

       

      This worked. However, as soon as I cut and paste it into P.L.B., Find/Change says there's no match.

      (?<=^\u{2,}\s\d+)\s


      The culprit seems to be the comma that comes right after the digit 2. If I take it out, I do get a match, but just not the one I wanted.


      Why doesn't P.L.B. accept the comma as part of the custom range in my grep definition?


      (FYI, I'd prefer to use wildcards with a specified range, rather than literal text.)

       

        • 1. Re: InDesign CC Grep Find/Change to replace space character with paragraph (pilcrow)
          [Jongware] Most Valuable Participant

          It indeed is the comma, and the reason this fails is because InDesign's flavor of GREP does not allow a variable length argument in its lookbehinds. And the construction "a{x,y}" indicates a variable length.

           

          For "CHAPTER" only, you know how many uppercase characters there are, and even the exact text, you can use

           

          (?<=^CHAPTER \d)\s

           

          for the first few single-digit chapters, and then

           

          (?<=^CHAPTER \d\d)\s

           

          for the rest. In your version of InDesign, I suppose there is also a solution possible with the fairly new \K "forget-me" operator but I've not yet got enough experience with that. It should look something like this:

           

          ^\u{2,}\s\d+\K\s

           

          but you'll have to experiment a bit to see how to get it to work with the replacement string.

           

          By the way, you should only use the name "pilcrow" for that one character that looks like this: "¶". The code you are inserting is simply called a "return" or alternatively "paragraph return". Initially I took your question literally, and it sounded as if you were after this result: "CHAPTER 22 ¶ SUNDAY BELOW GROUND"