2 Replies Latest reply on Apr 24, 2012 4:25 PM by kremisi

    GREP text selection between words

    kremisi Level 1

      I'd like to select all the text contained between [2A] and [F2A].

      The problem is that there are n paragraph between the 2 items as in the following example:

       

      [2A]

      Lorem ipsum dolor sit amet.

      [MOI] Lorem ipsum dolor sit amet.

      [ROI] Lorem ipsum dolor sit amet.

      [F2A]

       

      I tried:

      (\[2A\]).+(\[F2A\])

       

      But there are maybe more than one mistake in my code. Any suggestion?

        • 1. Re: GREP text selection between words
          [Jongware] Most Valuable Participant

          Put "(?s)" at the start of your GREP to force "single-line" mode.

           

          By default, GREP only works on a single paragraph, and so it will stop searching when it encounters a hard return. Setting single-line mode makes it treat the hard return as any other regular character.

           

          You might want to change the ".+" in the middle of your expression to ".+?", to make it match the shortest possible string. Default is GREP grabs as much as possible, so if you have these codes more than once in a text, it will happily select all from the very first to the very last instance.

          • 2. Re: GREP text selection between words
            kremisi Level 1

            I could not imagine the great Jongware replied to my post :-)

             

            The final code is:

            (?s)(\[2A\]).+?(\[F2A\])

             

            Thanks!