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

Selecting Next Paragraph following another one using Grep

Return to Member Forum

  • Author
    Posts
    • #60050

      I have a request (more a challenge than a real case) from a friend. He ask me if it was possible using Grep searching to select a paragraph (and apply a style) but only when this one is preceeded by another paragraph that contain a specific word.

      I can select the paragraph containing “myWord” with this:

      .*(?<=myWord).*/r

      or this

      .*myWord.*/r

      or this paragraph and the next one using this:

      .*(?<=myWord).*r.+$

      But what I need is only selecting the second paragraph. I'm lost… Is it possible?

      Thanks!

      Jean-Claude

    • #60051

      Cannot be done. (Admittedly, I've said that before on a number of occasions and got proven wrong …)

      The reason is, to apply your style only the next paragraph, you need a Lookbehind containing “myWord” and its own hard return. (Look, backslashes! One: r Two: \r Three: \r — you need to type two to insert one, and so on. :D ) But between the myWord and hard return, you need a non-quantifiable repeat-anything code — your dot-asterisk — and that makes the Lookbehind invalid. InDesign's GREP library just can't do it.

      If you need this in a real world situation and really can't afford to miss one, you'd probably work around it by first giving all paragraphs containing “myWord” a color, extending up to the paragraph return and one character beyond it (!), so you can search for “any character” in that particular color at the start of a paragraph.

    • #60055

      Hi Jongware!

      Good to see I was not looking at something obvious without seeing it. ;-)

      Thanks for your suggestions. I will give it a try.

      JC

    • #67736
      Masood Ahmad
      Participant

      It’s too late to revert back to the old post. I was just searching something and found this. JC, I hope you might have achieved this already. Your query is interesting, so I think to give it a try…

      Might be I’m wrong, could you please check and let me know if this is the right code for your query:

      Find what:
      (.+\r)(?=.*myWord.*)

      Change to: paragraph style of your choice.

      The code works fine for me unless you do not have blank lines in between. It applies a style to a paragraph if the next para contains myWord.

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