3 Replies Latest reply on Sep 14, 2016 4:34 AM by [Jongware]

    GREP lookbehind

    jakec88782761 Level 2

      Hi guys,

       

      I'm trying to write a GREP code which changes all instances of amputee(s?) which are not preceded by the words "bilateral, unilateral, trans-femoral and trans-tibial.

       

      My code looks like this:

       

      find:     (?i)(?<!bilateral|unilateral|trans-femoral|trans-tibial)amputee(s?)

      change to:     user$2

       

      The only thing I can think of is that you can't use the or operator within negative lookbehinds?

       

       

      Any help would be much appreciated

        • 1. Re: GREP lookbehind
          [Jongware] Most Valuable Participant

          You can use OR with negative lookbehinds, but due to limitations of the type of GREP that Adobe uses, you are not allowed to use anything that may result in strings of different lengths in a lookbehind. This is also the reason you cannot use '*', '+', and '?' in a lookbehind.

           

          You can however test for each item one at a time:

           

          (?i)(?<!bilateral)(?<!unilateral)(?<!trans-femoral)(?<!trans-tibial)amputee(s?)

           

          Since they appear in order, the net result is kind of AND instead of OR – not x and not y and not z instead of your not(x or y or z).

           

          A little added warning on your replace expression: lookaheads and lookbehinds are always parenthesized, but they are meant to not be a part of "the" search expression. So you should not count them for your replace-with $! In this case, you should simply replace with

           

          user$1

           

          as the only parenthesized group that gets 'found' is the one with the optional 's'.

          • 2. Re: GREP lookbehind
            jakec88782761 Level 2

            Thanks Jongware!

             

            I just tried that before your comment and it does work

             

            Is there also a way of keeping the original capitalization of the replaced word?

             

            For example if it said Amputee with a capital A, can I replace it with User with a capital U and visa versa?

             

            Many thanks,

            • 3. Re: GREP lookbehind
              [Jongware] Most Valuable Participant

              W.r.t. case sensitive: alas, no. This does work in the regular text Find & Change but not in GREP. You need to do the change twice, once with a capital and once with a lowercase.