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

GREP Bug in Lookaround?

Return to Member Forum

  • Author
    Posts
    • #84221
      dreerr
      Member

      Dear InDesign Secrets Users,
      I have a programming background, so I use Regex/GREP quite often in my projects. I’ve come across a problem in InDesign, which is _just not working_. Using the Syntax:

      (?<=~P)(.+?)~b(?=~b{2})

      In human language:
      [Positive Lookbehind for Page Break][Text][Return][Positive Lookahead of two Returns]

      The syntax ~P(.+?)~b~b{2} is working fine, it seems that any special characters starting with ~ are not honored by the Lookaround Regex syntax.

      Any solution on this? The reason I’m using Lookaround here is because I need to format Paragraph styles, so ~P and ~b{2} mustn’t be included in the result.

    • #84228
      Ari Singer
      Member

      Interesting.

      But it’s not the special characters starting with a tilde (~) that’s the problem. I tried using just the Standard Carriage Return special character (~b) in a positive lookahead and lookbehind respectively and they both worked fine.

      I’m afraid it’s because the page break is in the previous text frame and InDesign doesn’t regard it as being technically ‘before’ the text. But again, this is only in a positive lookbehind so I’m not sure what causes this.

    • #84260
      David Blatner
      Keymaster

      I don’t think positive lookahead can handle that kind of expression. In general, it can only handle looking for a very specific set of characters.

      • #84269
        Ari Singer
        Member

        @David: But why can the positive lookahead handle the Standard Carriage Return (~b)?

      • #84270
        David Blatner
        Keymaster

        I wasn’t clear in my answer. When I said “specific set of characters” I meant that positive lookahead has to look for characters that you specify. So, for example, you cannot use expressions such as a?c inside a positive lookahead because it’s not specific… it uses a wildcard.

        So it works when you look for a specific character, but not with an expression such as “one or more characters”

      • #84271
        Ari Singer
        Member

        I do know that. But what does it pertain to the issue at hand? The ~P is a specific character not a wildcard.

        P.S. By the way, as you know, there’s one exception to the rule. When you use negative lookbehind but by the better method (\K) it can search for wildcards. A shame there’s no equivalent for all other lookarounds.

      • #84280
        Matt Isaac
        Participant

        In my experiences, positive lookaheads do support wildcards; though they always search for the shortest match. If you used (?=a?c) “positive lookahead of zero or one a followed by a c” it will search instead for “positive lookahead of a c” since the shortest match of “a?c” is “c”.

        That being said.. In dreerr’s original expression “(?<=~P)(.+?)~b(?=~b{2})” the “(.+?)~b(?=~b{2})” part of the expressions does what it should in selecting any text followed by a carriage return that comes before two carriage returns. The only thing throwing the expression off is the positive lookbehind of a page break. which goes back to Ari’s original reply as positive lookbehinds being unable to look to a previous text frame.

        Though as a workaround you can apply the paragraph style to “(?<=~P)(.+?)~b(?=~b{2})” then go through and remove the paragraph style from “.+~P(?=.+~b{3})”. It’s a bit more work but it does work in the end.

      • #84286
        David Blatner
        Keymaster

        Dang, you’re correct that a single wildcard character can be used inside a positive lookahead. I stand corrected. (Well, sit corrected, technically.)

        However, I just tested a positive lookbehind that looks for something in a previous frame and it worked fine.

      • #84287
        Ari Singer
        Member

        So I’m afraid it’s just a bug. We need Peter Kahrel here.

    • #84288
      dreerr
      Member

      Here a short update from my side:
      Talked the Peter, he confirmed that he had a similar situation with the ~v variable marker. After filing a bug report Adobe mailed me for more information on the subject in question.
      Working around that problem isn’t the question of this thread, of course it is very easy to come up with the desired solution and I already did ? The only question for me is why this wasn’t already fixed long ago and my guess is that it has to do with an incomplete implementation…

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