11 Replies Latest reply on Jul 4, 2014 5:34 AM by Peter Spier

    GREP for runts

    Peter Stnsz

      Hi,

       

      I was working around the GREP that will be nested in body style ('No Break' char style). What I want to achieve is 'kill' the runts in a proper way. So far I manage to keep together minimum 7 (this is my requirement) characters excluding spaces with the code as follows:

       

      [^\s].{1,7}[^\s]$ 
      

       

      That's work fine but what when I'd like to match [[:alpha:]] only, excluding punctuations? Logic says that I should replace operator '.' with [[:alpha:]] and for the 'exclusion brackets' i should use for instance \p{P*} but this does not to seem to work.

       

      Any suggestions?

       

      Thanks a lot!

        • 1. Re: GREP for runts
          Peter Spier Most Valuable Participant (Moderator)

          Have you tried [[:alpha:]]{1,7}[[:punct:]]*$

           

          This is going to fail, however, if your paragraph ends with a number or whitespace.

          • 2. Re: GREP for runts
            Peter Stnsz Level 1

            Hi Peter,

             

            The thing is that I want to exclude space characters. For instance you may have at the end of paragraph something like unit (0,3 ml) - second phares indeed contains 7 non-space characters but I would like to GREP to exclude all the type of punctuation and 'force' the text to be No Break so unit (0,3 ml) will be kept together too.

             

            Thanks!

            • 3. Re: GREP for runts
              Peter Spier Most Valuable Participant (Moderator)

              I think that's just too variable to set up as a GREP expression.

               

              What's wrong with including the spaces if you don't want them to break? Why not use [^\s].{6}$ which finds seven character at the end of the paragraph not starting with a space (but will fail if there are six characters preceded by a space).

              • 4. Re: GREP for runts
                Peter Spier Most Valuable Participant (Moderator)

                Or maybe this is less generic and can be done as \s*\(.+\)?$ which should keep together any string enclosed in parentheses at the end of a paragraph, along with any whitespace immediately before it. This, too, has potential problems if your paragraph ends in a long parenthetical phrase (which could be too long for the column width as in this paragraph)

                • 5. Re: GREP for runts
                  Peter Stnsz Level 1

                  Hi,

                   

                  Yes my GREP has evolved from the .{7}$ so your example is quite similar to mine. The reason why I want to achieve this is my customer requirement. I have to deal quite often with different languages that include one character words or such before any unit or say 'mathematical function'. I am doing that so far manually and looking for solution that will allow me use nested GREP style.

                   

                  Your second example \s*\(.+\)?$  may not work well when I have something included within '[ ]' or '{ }' brackets, so I would rather go for general punctuation string.

                  • 6. Re: GREP for runts
                    Peter Spier Most Valuable Participant (Moderator)

                    I continue to think this is too complicated to do as a single GREP style, but it would help if you gave us a list of examples of perhaps a dozen cases.

                    • 7. Re: GREP for runts
                      Sandee Cohen Adobe Community Professional

                      I don't know much about GREP but can't you set a second GREP nested style for the same No Break character for just that unit expression?

                       

                      unit (\d,\d ml)

                       

                      I don't know what other variables you have for these unit expressions, but I think you can just make as many as you need.

                      • 8. Re: GREP for runts
                        Peter Spier Most Valuable Participant (Moderator)

                        Yep.

                         

                        You could also use classes for the parentheses/brackets/braces to make them interchangeable, but it isn't at all clear to me that what needs not to break is always the same length or format.

                        • 9. Re: GREP for runts
                          Sandee Cohen Adobe Community Professional

                          I'm not clear on it either. We might need some + signs in there.)

                          • 10. Re: GREP for runts
                            Peter Stnsz Level 1

                            Peter Spier wrote:

                             

                            I continue to think this is too complicated to do as a single GREP style, but it would help if you gave us a list of examples of perhaps a dozen cases.

                            Hi,

                             

                            Had no time before but these are some of the examples that are used:

                             

                            5 x 0,4 ml.

                            or in 2 ml.

                            i w 2 ml.

                            or (0,3) u.

                            as in [0,1].

                            or [2:1].

                             

                            So the point is to keep the preceding words with the runts mentioned above. Sometimes {} brackets are used too that's why I am looking for 'flexible' code.

                            • 11. Re: GREP for runts
                              Peter Spier Most Valuable Participant (Moderator)

                              One of the GREP aces like Jongware might have some idea, but I just don't see any sort of pattern here that would make this possible. The best I think you can do is set no break on an absolute number of characters before the end of the paragraph, and perhaps add a second GREP to prevent breaking the expressions in any type of bracket, but I don't see that as being terribly useful if you've already applied the no break to the characters where they would fall.