5 Replies Latest reply on May 6, 2012 6:28 AM by Trevorׅ

    Boolean (Conditional) Greps

    Trevorׅ Adobe Community Professional

      How can I make a condition for a grep?


      For example all capitol letters except for the letter "S"

      or all spaces except for hair width spaces.



        • 1. Re: Boolean (Conditional) Greps
          Peter Spier Most Valuable Participant (Moderator)

          As far as I know (but there are other users here with more knowledge of GREP) you can't do that. You can negate an entire class, or create a class of things you want to match, but you cannot create an exception to a class.

          • 2. Re: Boolean (Conditional) Greps
            Trevorׅ Adobe Community Professional

            Thanks Peter


            I've been reading through (almost finished) Peter Kahrel's excellent guide to Greps in Indesign http://shop.oreilly.com/product/9780596156015.do and couldn't find anything on it so it probably can't be done!


            I'll see if anybody has any other Ideas


            In the mean time I'll try to script it.  Doesn't sound to hard. If I have success I'll post it here.

            • 3. Re: Boolean (Conditional) Greps
              [Jongware] Most Valuable Participant

              The easiest way of excluding something with GREP is not to search for it in the first place


              [A-RT-Z] will match all regular capitals except for the 'S'.


              [~m~>~f~S~s~<~/~.~3~4~%\x{20}] matches all spaces except Hair Width space (this is the built-in Multiple Space to Single Space query, minus the Hair Width code ~|


              A more advanced way to specifically exclude something is using Lookahead or Lookbehind. Usually, you would put a Lookahead at the end of an expression, to match something only if it's followed by the Lookahead item, but you can do some tricks with it if you put it at another place:




              This will match any uppercase character (including Greek and Cyrillic), but the Negative Lookahead ensures it will not match the exact character 'S'. Similarly,




              matches any whitespace except the hair width.


              If in addition you also want to exclude any accented form of the letter "S", you would use




              -- the code [[=s=]] stands for 'any equivalent of "s"', which includes s and S, and also Ș and ś, and other accented forms (but not Cyrillic 'с' or Greek 'Σ', since those are not forms of the Latin S).


              These examples only work one character at a time. You can repeat them, but you must pay attention to what you repeat:




              will match "any uppercase character-not-S", followed by any arbitrary long string of all uppercases. The Lookahead is only tested for the first occurrence. To make it do what you (probably) intend, instead use



              • 4. Re: Boolean (Conditional) Greps
                Trevorׅ Adobe Community Professional

                Thanks Jongware !!


                After reading your answer twice and taking in to consideration my the amount of sleep I got (or more importantly didn't get  last night) I shall look it over after lunch


                Will get back after that.

                • 5. Re: Boolean (Conditional) Greps
                  Trevorׅ Adobe Community Professional

                  Finished lunch - Yummy


                  Great answer


                  It's 10/10 for what I asked, i.e. how to find a group with exclusions.


                  What I didn't ask was how to find things that are this AND that.


                  For example mark characters that are in the unicode range of 05B0-05C4


                  Well after such a Yummy lunch I'm not such a Dummy and figured out one has to use the positive look ahead.




                  (Credit to you also for the \p{Mn} for marks Thanks)