4 Replies Latest reply on Sep 20, 2016 3:11 AM by tpk1982

    Find punctuation using GEP

    tpk1982 Level 4

      Hi,

       

      I need to find the punctuation after italic word. I am not sure it is possible or not.

       

      The punctuations after red colored text need to find. Please help.

      Screen Shot 2016-09-20 at 11.13.51 AM.png

       

      The below GREP give all the punctuations

       

      (?<=\w)[[:punct:]]

       

      Thanks,

      K

        • 1. Re: Find punctuation using GEP
          Peter Kahrel Adobe Community Professional & MVP

          1. Look for .[[:punct]]

          2. Iterate through the found instances: e.g.

           

          found = app.documents[0].findGrep();
          for (i = 0; i < found.length; i++) {
            if (found[i].characters[0].fontStyle === 'Italic') {
                // ....
            }
          }
          

           

          Peter

          • 2. Re: Find punctuation using GEP
            tpk1982 Level 4

            Hi Peter,

             

            Thank you so much. Below is the finished coding. Is it okay or it will create any problem in future?

             

            app.findGrepPreferences = null;    app.changeGrepPreferences = null; 
            app.findGrepPreferences.findWhat=".[[:punct:]]";
            found = app.documents[0].findGrep(); 
            alert(found.length)
            for (i = 0; i < found.length; i++) { 
              if (found[i].characters[0].fontStyle === 'Italic') { 
                found[i].characters[1].fontStyle="Regular"
              } 
            }
            

             

             

            Thanks,

            K

            • 3. Re: Find punctuation using GEP
              Obi-wan Kenobi Adobe Community Professional

              Hi Kartik,

               

              I'd try to be a little more vigilant and would proceed in 3 steps:

               

              1/ Find all occurrences of a character followed by a punctuation.

              2/ Mark [with a condition] all occurrences of a character in italic followed by a punctuation.

              3/ Check - manually - if they are valid or not.

               

              e.g.:

               

              "My great master was Yoda! I miss him!"

               

              vs.

               

              "My name is Obi-wan Kenobi! I'm a Jedi Master!"

               

              [to be corrected in the first case, not in the second]

               

              (^/)

              1 person found this helpful
              • 4. Re: Find punctuation using GEP
                tpk1982 Level 4

                Hi Obi,

                 

                Thank you for the suggestion. My requirement is finding italic word and following punctuation, depending upon my need i may convert the punctuation as italic or regular.

                 

                With my above code, i added a dialog box and ask the user which i need to apply.

                 

                But my challenge for now is, sometimes the font don't contains regular style, so i decided to create a style and apply.

                 

                like below:

                 

                function mypunct_change(){
                var w = new Window('dialog',' Punctuation Change'); 
                    w.p1= w.add("panel", undefined, undefined, {borderStyle:" Punctuation Change"}); 
                    w.p1.add('statictext',undefined,"Select the style you want to change");
                    w.p1.g = w.p1.add('group'); 
                    w.p1.g.orientation = 'column'
                    w.p1.g.alignChildren = "left";
                    var mySetCheckbox = w.p1.g.add('radiobutton {text: "Regular", value: true}') 
                      var mySetCheckbox1 = w.p1.g.add('radiobutton {text: "Italic"}') 
                   
                    w.p1.g1 = w.p1.add('group');     
                    w.p1.g1.orientation = 'row'
                    var myOKButton = w.p1.g1.add('button {text:"OK"}')
                    var myCancelButton = w.p1.g1.add('button {text:"Cancel"}')
                       
                   
                var myResult = w.show()
                
                
                    if(myResult == 1){
                        if(mySetCheckbox.value==true){
                        app.findGrepPreferences = null;    app.changeGrepPreferences = null; 
                        app.findGrepPreferences.findWhat=".[[:punct:]]";
                        found = app.documents[0].findGrep(); 
                        for (i = 0; i < found.length; i++) { 
                          if (found[i].characters[0].fontStyle === 'Italic') { 
                            found[i].characters[1].fontStyle="Regular"
                          } 
                        }
                        app.findGrepPreferences = null;    app.changeGrepPreferences = null; 
                        }
                        else if (mySetCheckbox1.value==true){
                              app.findGrepPreferences = null;    app.changeGrepPreferences = null; 
                        app.findGrepPreferences.findWhat=".[[:punct:]]";
                        found = app.documents[0].findGrep(); 
                        for (i = 0; i < found.length; i++) { 
                          if (found[i].characters[0].fontStyle === 'Italic') { 
                            found[i].characters[1].fontStyle="Italic"
                          } 
                        }
                        app.findGrepPreferences = null;    app.changeGrepPreferences = null; 
                            }   
                      }
                
                
                    else if (myResult== 2){
                      alert("You clicked Cancel!");
                      exit(0);
                    }
                }
                

                 

                Thanks,

                K