Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Requesting help with GREP Look Behind …

Return to Member Forum

  • Author
    Posts
    • #65739
      gamouning
      Member

      Hi,

      I wish to apply a paragraph style called “Second Line after Chapter Title” every occurrence of “CHAPTER xxx” appears, where xxx is ONE, TWO, THREE, etc upto Forty. I believe this is a job for the GREP Look Behind Find/Replace. Thanks in advance for your assistance.

      -Greg

    • #65756

      No need for a GREP, you can search for “CHAPTER” with a regular Find/Change. (Mind to check both “Case Sensitive” and “Whole Word” boxes. (Also mind to *uncheck* them when you’re done, as that is the default state everyone is used to.))

      Can you explain what the lookbehind part was supposed to do? You can search for ‘ONE’ with “CHAPTER” in the lookbehind like this:

      (?<=CHAPTER )ONE

      … but I don’t see any advantages in this. Since you are applying a paragraph style, there is no need for a lookbehind (or lookahead, for that matter), because what you are looking for *is* in the same paragraph.

      • #65772
        gamouning
        Member

        Thanks Jongware for your prompt reply. Actually, I have a total of 40 paragraphs which are not numerals but spelled out (ONE, TWO, THREE, etc.). So, I want to skip over this information and apply the paragraph style to the next paragraph not the one which contains “CHAPTER ONE”.

        Ultimately, I would like to accomplish this using a GREP style and not Find/Change if that is possible.

        Regards,
        Greg

    • #65789

      Then you have *two* problems …

      First off: GREP Styles cannot help you with this, in any way. They CANNOT apply a paragraph style, and they CANNOT apply or check anything outside of their own paragraph. They live in a small, one-paragraph-sized world of their own.

      Second: alas, your suggested GREP wouldn’t work either! The basic idea would look like this:

      CHAPTER \u+\r.

      (the last full stop is important!) Other than my example above, this now also contains ‘all uppercase, any number of them’, so it can match ‘ONE’, ‘TWO’, and ‘THREE’; and if you try it, you will see it grabs a chapter plus number, a next hard return, and a single character of the next paragraph. Should you apply a paragraph style now, then it gets applied to both paragraphs.

      But you only want to grab the second, so that’s why you suggested a lookbehind (that’s the part I initially missed). Moving the part before the to-be-adjusted paragraph into a lookbehind, you would get this:

      (?<=CHAPTER \u+\r).

      and this *ought* to find a single character, with ‘CHAPTER’ (etc) on the line above. But it does not work! The reason is your capitalized numerals have different lengths — ‘ONE’ is 3 characters, ‘TWO’ also 3, and ‘THREE’ has 5 — and a lookbehind cannot test for a variable length of characters. This is just too complicated for a single GREP.

      A possible (and tricky) solution is to do multiple tests, each one with a fixed length:

      ((?<=CHAPTER \u\u\u\r)|(?<=CHAPTER \u\u\u\u)|(?<=CHAPTER \u\u\u\u\u)).

      will work for ONE up to TEN (for ELEVEN and/or TWELVE you need to add a 6-uppercase check, after that 8, and so on and so forth).

    • #65796
      Matt Mayerchak
      Participant

      Jongware wote:

      “a lookbehind cannot test for a variable length of characters. This is just too complicated for a single GREP.”

      I believe this may provide a clue to why I’m having trouble with a completely different GREP search of my own . . . Is this documented somewhere, or do you know this just from experience?

    • #65800

      Matt, it’s one of those things that I tried and tried and then *finally* googled … and what do you know, Benny Hill was right:

      They said that it could not be done,
      He said, “Just let me try.”
      They said, “Other men have tried and failed,”
      He answered, “But not I.”

      They thought that it could not be done,
      Some even said they knew it,
      But he faced up to what could not be done…
      And he couldn’t bloody do it!

    • #65809
      gamouning
      Member

      Thanks Jongware. Perhaps my search can be redefined? What happens if I search for the next paragraph that follows a specific paragraph style? For example, locate the next paragraph after paragraph style called Chapter Title. Is there a GREP instruction for doing this?

    • #65817

      Can’t do that either — GREP does not handle different paragraph styles. Doesn’t my mentioned “possible (tricky)” GREP work?

    • #65862
      gamouning
      Member

      Hi Jongware,

      Yes, I was able to get your “possible (tricky)” GREP to do work after some minor changes. Here is the revised version for the first 10 Chapters:

      ((?&lt=CHAPTER \u\u\ur)|(?&lt=CHAPTER \u\u\u\ur)|(?&lt=CHAPTER \u\u\u\u\u\r))+.*r

      Hopefully I got all of the escapes and parenthesis to appear.

      -Greg

Viewing 7 reply threads
  • The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
Forum Ads