9 Replies Latest reply on Feb 24, 2012 7:13 AM by Peter Spier

    Two problems with a grep solution?

    Maggern78

      Hello!

       

      I have two problems that I need some help with. I've been searching around for solutions, but are unsure what approach that is the best:

       

      A: I need a new (or next) paragraph style after TWO hard line breaks. How do I do this? Do i search for two line breaks in GREP and replace it with a "end of paragraph"? Or do I need scripting for it?

      See the attached file for the actual layout solution. "1" is the current situation, and I want it to automaticly be "2".

       

      paragraph.jpg

       

      B: We have just implemented a new text editor/system and it lacks a feature: In the body text there is no styling/labeling for "paragraph title". In other words, the paragraph titles show up in Indesign as plain body text.

      This is a big source of error. So: Is there any way to search for sentences that lacks period (.) and change their styling? The paragraph titles are the onlye sentences without periods in the whole text.

       

      subheading.jpg

       

      I'll be VERY happy it someone can point me in the right direction, or provide a solution.

       

      Regards,

      Magnus

        • 1. Re: Two problems with a grep solution?
          Peter Spier Most Valuable Participant (Moderator)

          For case A, it sounds to me like you are saying every third paragraph should have one style, and the wo interving should ahve a different style. If that's the case, and it's always tru that paragraphs follow this pattern, this is a problem that is solves with paragraph styles, not GREP. Yoou need three styles, with Next style set in each one so that the first style is followed by the second, the second by the third, and the third by the first, forming a cycle. Style three can be based on style two if the formatting is the same, and just change the name and the next style.

          • 2. Re: Two problems with a grep solution?
            Peter Spier Most Valuable Participant (Moderator)

            Part B seems simple on the surface, but probably isn't. I'm sure that you will potentially run across a sentence at the end of some text someplace that end in an exclamation point or a quotation mark, or a colon, so it probably is not enough to search for missing periods. Instead I think you should look for end-of-paragraph not preceded by any punctuation. I'm not sure, however, if one can use a class in a negative look-behind. Perhaps Jongware will be kind enough to let us know.

            • 3. Re: Two problems with a grep solution?
              [Jongware] Most Valuable Participant

              You are getting familiar with the lingo, Peter! You are correct: you can use a class in a negative lookbehind. This GREP

               

              (?<![.,!])$

               

              will find an end-of-paragraph where there is no period, comma, or exclamation before. But it has a few problems, though -- it doesn't "mark" anything as found, and InDesign does not like it. A solution is to find any character-which-is-not-punctuation:

               

              [^.,!]$

               

              If you are sure you want to skip all punctuation, you could try the built-in class name "punctuation":

               

              [^[:punct:]]$

               

              .. but I just saw a bit of an unexpected side effect: a hard return (which is "any code followed by the end of a paragraph", if one is applying the formula to the letter) also is "not punctuation" (again playing strictly by the rules). And you Can't Argue with the rules. So, alternative #1 would be to work around it with

               

              [^[:punct:]\r]$

               

              which is 'everything except punctuation OR a hard return'. Or let's forget all about that pesky punctuation-not-punctuation and search for a word character at the end of a paragraph:

               

              \w$

              • 4. Re: Two problems with a grep solution?
                Maggern78 Level 1

                Hello Peter! Thanks for your reply!

                 

                I've aldready considered "cycling" through some paragraph styles as you suggest, but as the number of paragraphs between the two line breaks are random (usually between 3-6) this is not a perfect solution.

                • 5. Re: Two problems with a grep solution?
                  Maggern78 Level 1

                  Part B seems simple on the surface, but probably isn't. I'm sure that you will potentially run across a sentence at the end of some text someplace that end in an exclamation point or a quotation mark, or a colon, so it probably is not enough to search for missing periods. Instead I think you should look for end-of-paragraph not preceded by any punctuation. I'm not sure, however, if one can use a class in a negative look-behind. Perhaps Jongware will be kind enough to let us know.

                   

                  Thanks again Peter. I totally forgot about ?, !, and : so thanks for pointing that out for me!

                  • 6. Re: Two problems with a grep solution?
                    Maggern78 Level 1

                    Thanks for you answer Jongware!

                     

                    When grep expression [^[:punct:]\r]$ or w$ has found the last character at the end of the paragraph, how do I ensure that all the characters/words on that line is selected?

                    • 7. Re: Two problems with a grep solution?
                      [Jongware] Most Valuable Participant

                      You want to apply a paragraph style, so you don't need to "select" the entire paragraph. InDesign can only apply a Paragraph Style to an entire paragraph, so it will do it correctly whatever you have selected.

                      • 8. Re: Two problems with a grep solution?
                        Peter Spier Most Valuable Participant (Moderator)

                        I was thinking some more about this after I woke up this morning (and before seeing the overnight suggestions), and wondered if a better method of attack might just be to look for ay word character at the end of a paragraph, like this: \w$

                         

                        Presumably any other character tells you it isn't a heading. Of course this fails on trailing whitespace, but so I think does the other.

                         

                        About part A, if you have a random number of intervening paragraphs, I think you are stuck changing the styles manually. GREP cannot solve that problem.

                        • 9. Re: Two problems with a grep solution?
                          Peter Spier Most Valuable Participant (Moderator)

                          I should have said GREP cannot solve that problem UNLESS there is something unique about those paragraphs that need to be changed, that has nothing to do with position in the text, that you can identify with a GREP search.