5 Replies Latest reply on Mar 2, 2017 2:53 AM by Obi-wan Kenobi

    Grep - How to find non-italics characters followed by italics

    wahabm25434365

      Hello everyone...

       

      Is there a way to grep all non-italics characters followed by an italics punctuatiob, e.g., serach for "Review of Religions," in this word, the punctuation "," is not italics, I would like to serach of all types of punctuation that are not italics, and change them to italics, same would be the case for bold, and bold-italics.

       

      Another way looking at it would be a grep that could search for any italics character followed by a regular punctuation, and a bold character follwed by a non-bold punctuation, and a bold-italics character followed by a non-bold-italics character.

       

       

      Thanks in advance!

        • 1. Re: Grep - How to find non-italics characters followed by italics
          Michael Witherell Adobe Community Professional

          I would run this 3 times:

          Find What: (\,|\;|\:)

          Find Format: Regular

          Change To: leave blank

          Change Format: Character Style Italic

           

          The second time you run it I would reset to Bold Character Style.

          The third time I would run it I would reset to Bold Italic Character Style.

           

          Automatic? No. But it would allow you to inspect each occurrence, and it would only take 5 minutes.

          • 2. Re: Grep - How to find non-italics characters followed by italics
            gert verrept Level 2

            Look for grep manager script or the multi find and change from automatication. The first is free. Once you have the query you can load them in a set and ececute them all in one click.

            • 3. Re: Grep - How to find non-italics characters followed by italics
              Peter Kahrel Adobe Community Professional & MVP

              This is not something you can just like that with InDesign's Grep. The Grep manager that Gert mentioned can't do that, don't know about Automatication's solution. If Michael's solution doesn't work for you, you can change italic formatting to text tags, so that this:

               

              Review of Religions,

               

              (where the comma is not italic) is rendered like this:

               

              <i>Review of Religions</i>,

               

              You can then search for (</i>)([[:punct:]]) and replace with $2$1 to move the punctuation inside the italics. Then you change the italic tags back to italic formatting. This method is described in detail in https://indesignsecrets.com/issues/issue-76-publish-anywhere. You'd do that again for bold and bold-italic. You can store the queries and rerun them. It's a method I've been using a lot, and it works well.

               

              Peter

              • 4. Re: Grep - How to find non-italics characters followed by italics
                gert verrept Level 2

                Peter, you're right. It cannot be done by either. I thought it could be chained, but no. The Grep manager and the MFC are useful solutions when grep queries can be executed one after the other. We use it a lot during layout of texts coming from Word.

                • 5. Re: Grep - How to find non-italics characters followed by italics
                  Obi-wan Kenobi Adobe Community Professional

                  Hi,

                   

                  Just this:

                   

                  app.findGrepPreferences = null;
                  app.findGrepPreferences.findWhat = ".[.,;:!?…]";
                  myFound = app.activeDocument.findGrep();
                  var F = myFound.length;
                  for (var f = 0; f < F; f++) {
                      var myCharStyle = myFound[f].characters[0].appliedCharacterStyle;
                      if (myFound[f].characters[-1].appliedCharacterStyle !== myCharStyle) myFound[f].characters[-1].appliedCharacterStyle = myCharStyle;
                      }
                  app.findGrepPreferences = null;
                  

                   

                  Of course, if you only want to catch "Italic", "Bold" and "Bold Italic" and avoid to catch, say, URL, you could play this:

                   

                  app.findGrepPreferences = null;
                  app.findGrepPreferences.findWhat = ".[.,;:!?…]";
                  myFound = app.activeDocument.findGrep();
                  var F = myFound.length;
                  for (var f = 0; f < F; f++) {
                      var myCharStyle = myFound[f].characters[0].appliedCharacterStyle;
                      if ((myCharStyle.name == "Italic" || myCharStyle.name == "Bold" || myCharStyle.name == "Bold Italic") && myFound[f].characters[-1].appliedCharacterStyle !== myCharStyle) myFound[f].characters[-1].appliedCharacterStyle = myCharStyle;
                      }
                  app.findGrepPreferences = null;
                  

                   

                  Capture d’écran 2017-03-02 à 11.39.36.png

                   

                  (^/)