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

LookBehind/LookAhead with Repeat

Tagged: 

Return to Member Forum

  • Author
    Posts
    • #75367
      Masood Ahmad
      Participant

      Hey you all there, I have an interesting query to dig into.

      As you might know that we can’t use the Repeat meta-characters with the lookbehind/lookahead Match expressions. For example:

      We cannot use the Repeat Meta-characters for varied length, like:
      (?<=\d+)
      OR
      (?<=£\d+)
      These will not work.

      However, We can use these codes, where the digit is of three digits, i.e. fixed length:
      (?<=\d{3})
      OR
      (?<=£\d{3})

      So my question is how you can tackle such issues where you don’t know the length of the digits and you have to use the lookbehind/look ahead.

      Looking forward for your suggestions and ideas…

    • #75377
      Aaron Troia
      Participant

      Masood,

      Yeah, Lookbehinds are non-greedy and kind of a pain when you are needing it to be greedy, one way to get around it is to use Keep or \K, it’s similar to a lookbehind but allows you to be greedy with your search, for example if you wanted to change this tab to a space but dont know how deep your list goes:

      \d+\.\K(?=.+?$)

      The Keep works pretty much the same way as a lookbehind and it adds the functionality of being non-greedy. Anyway play with the \K, it should do what you are wanting it to.

    • #75385

      Lookaheads with variable length are perfectly reliable. It’s just lookbehinds that suffer from this.

    • #75387
      Masood Ahmad
      Participant

      Thanks Ron, the code does the trick. I knew about \K but never tried it. Today I got an error while testing it in CS5, then I realized that it might work in higher version and it did. Thanks again.

      You are right Jongware, I thought, since Lookbehinds are not allowing the repeat so do the Lookaheads will, as they are the two faces of the same coin.

      But doesn’t it feel unjustified with the Lookbehinds? Why are they not allowed to feel the same? It might be a bug and could be rectified by Adobe, someday.

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