6 Replies Latest reply on Jun 19, 2013 6:25 AM by Peter Spier

    Prevent 1-2 letter words at end of lines?


      Hello everybody! Just a simple question:


      How do I use GREP styles to prevent 1 and 2 letter words at the end of lines? I haven't figured out yet how to do that...

      Also, is there any good GREP resource to learn about expressions?



        • 1. Re: Prevent 1-2 letter words at end of lines?
          Eugene Tyson Adobe Community Professional & MVP

          Make a character style and only check the "No Break" box - leave everything else blank.




          \w+ any word

          \s is a space


          \b - looks for a word boundary

          \w is any letter

          {1,2} means 1 or 2 leters, if you change this to {1,3} you will find 1 to 3 letters


          That means it will only look for a word boundary of 1,2 letters in a word group.



          (?=) is a positive look ahead so it's only searching ahead for two things


          [[:punct:]] - means any punctuation

          $ means at the end of a paragraph



          Altogether means that it's only looking for

          Any word

          1 or 2 letters within a word boundary that is definitely followed by any sort of punctuation at the end of a sentence.


          Then apply the character style No Break

          • 3. Re: Prevent 1-2 letter words at end of lines?
            Graphirus79 Level 1



            Thanks for the example of GREP expression writing! Sadly, it's not solving what I wanted so I guess I didn't express myself right in the first place...

            In Russian there are certain 1 letter words that should not be left at the end of lines in a paragraph, please take a look at the example here:

            Screen Shot 2013-06-19 at 4.09.38 PM.jpg

            In my example there are 2 instances of the russian character "и" where it sits at the end of a paragraph... I need an expression to put it automatically on the next paragraph.


            Thanks again!

            • 4. Re: Prevent 1-2 letter words at end of lines?
              SJRiegel Adobe Community Professional & MVP

              Maybe this will work for you. It will find any one or two letter word, the space after it, and the next word.

              You can apply your no-break style to that, and it will prevent those words from sitting at the end of a line by creating a non-breaking string with word directly after.


              • 5. Re: Prevent 1-2 letter words at end of lines?
                Graphirus79 Level 1

                That expression works like a charm! Thank you!

                • 6. Re: Prevent 1-2 letter words at end of lines?
                  Peter Spier Most Valuable Participant (Moderator)

                  I'm not sure that really does what you want. It's not isolated to the ends of lines, and if you apply no break to that string any word following a one- or two- character word will also be prevented from breaking, so a string something like "or multiple syllables in following words" cannot break the word multiple at the end of a line.


                  I was playing with something similar turning off multi-line mode, which is supposed to convert the $ to end of line: (?-m)\<\w{1,2}\s$ but it fails to find any match. Without the $ if finds all one- or -two cahracter words followed by a space (but you don't need to turn off multi-line mode to do that, so \<\w{1,2}\s works the same way). That might actually be "good enough" since it will keep all one- or two-character words with wahtever follows (becasue the space between becomes non-breaking), but allows the following word to break if necessary.


                  Notice too that the second word boundary marker isn't really necessary -- the \w{1,2}\s takes care of ending the word on its own.


                  If some GREP expert would care to weigh in on why the $ didn't work in single line mode, I'd love to hear it.