5 Replies Latest reply: Oct 5, 2010 7:23 AM by Eugene Tyson RSS

    Can Grep do this for me?

    Maria964 Community Member

      Hi guys, I am back!

       

      I wonder if Grep can solve this problem for me -- I'm going to call it "Avoiding Widow Line Characters" -- and what I need is this:

       

      capture.jpg

       

      A search that grabs any single character (letter or number) and the corresponding next white space at the end of every line in a paragraph (the red circles) but excludes the last one (red rectangle).

      I know a little of Grep but this one exceeds my capabilities so, if any one can help a girl with a problem it will be wonderful.

      Thank you in advance

      Maria

        • 1. Re: Can Grep do this for me?
          Eugene Tyson CommunityMVP

          You do a search for a SPACEs followed by ONE SINGLE CHARACTER followed by a SPACEs

           

          Which would be

           

           

          Find

          \s+(.)\s+

           

          Change to

          ~S$1~S

          • 2. Re: Can Grep do this for me?
            [Jongware] Community Member

            .. Unfortunately, no.

             

            Eugene, the Hard Return is also a 'space' character; Maria's red rectangled marker would also get picked up. The simple solution would be to not use \s, but type a regular space instead -- but that won't work either!

             

            Maria, GREP can do a lot but it cannot locate the end of a line, only that of a paragraph. So there is no way to distinguish between your marked end-of-line single characters, and the single character in line #3. For GREP, the entire paragraph is treated as a single long line up to the Hard Return.

            • 3. Re: Can Grep do this for me?
              [Jongware] Community Member

              On second thought, I think you don't want to search-and-replace but just want those single characters to be kept together with the next word ...

               

              That is quite easy with a GREP style (have we mentioned those before?). Create a Character Style containing just No Break -- leave all other settings blank. Then create a GREP style, applying this No Break style to

               

              \<\w \w

               

              (note there is a single regular space in the middle).

               

              It has a sort of unexpected side-effect: a sequence of "a b c d" is not grabbed into one long string, but rather into two separate ones: "a b" "c d". As a consequence, this line may be broken between the two pairs, which I think is very fortunate!

               

              But if you don't want that, use this GREP instead:

               

              \<\w (?=\w)


              -- it will keep any long sequence of loose letters together, so it may result in overset text in extreme cases.

              • 4. Re: Can Grep do this for me?
                Maria964 Community Member

                Thank you Jongware and Eugene,

                 

                I had forgotten to mention that I was really looking for is a grep style to avoid single letters at the end of paragraph lines.

                 

                But Jongware, who besides being a magician with scripting, can also read minds through the net, solved the problem. In the midlle of the paragraphs there will be some "no breaking" but I think Indesign can cope with that.

                 

                Thank you again Jongware and Eugene

                • 5. Re: Can Grep do this for me?
                  Eugene Tyson CommunityMVP

                  Ahrgh - why would it include a paragraph return as a white space? Silly GREP.

                   

                  Well if you change the \s to a space character with the space bar then it works ok.

                   

                  +(.) +