2 Replies Latest reply on Dec 4, 2012 5:31 AM by SimonLinden

    GREP repeat inside look behind

    SimonLinden

      I can't figure out why my GREP won't work.

      (?<=^\s*\d+)[\l\u]

      I want to find any paragraph which starts with zero or more spaces, followed by one or more digits which is followed by any letter. But I only want to select the letter (to check it's formatting and apply paragraph styles accordingly), and not the spaces/digits. However, it seems like I can't use the + and * operators inside a lookbehind function since these searches don't reveal anything.

       

      The following expression works, but it includes the spaces and digits:

      (?<=^)\s*\d+[\l\u]

       

      And this works but only works for two initial spaces and one digit:

      (?<=^\s\s\d)[\l\u]

       

      I could manually change the expression to match the four different ways that are needed in my document but I'd prefer it if it can be solved with just one expression.


        • 1. Re: GREP repeat inside look behind
          [Jongware] Most Valuable Participant

          Lookbehinds have to be of a fixed length, so you cannot use any of the operators +, *, or ?. In addition, behavior with OR strings of different lengths is, well, "undefined" (From memory: I think only the longest string gets considered?)

           

          For a simple query, one or two digits for example, you could use the OR operator like this:

           

          ((?<=\s\d)|(?<=\s\d\d))[[:alpha:]]

           

          but you are talking about *any* number of spaces followed by *any* number of digits. That's a lot of OR combinations.

           

          SimonLinden wrote:

           

          ..  this works but only works for two initial spaces and one digit:

          (?<=^\s\s\d)[\l\u]

          I could manually change the expression to match the four different ways that are needed in my document ..

           

          If it's just four, are those One or two spaces, one or two digits? That ought to be possible.

          • 2. Re: GREP repeat inside look behind
            SimonLinden Level 1

            Ok, that's good to know. I'll have to use the OR operator then.