11 Replies Latest reply on Mar 27, 2017 3:47 PM by Obi-wan Kenobi

    GREP code

    thaero17058

      Hello

      Are there any GREP code find words located at the beginning of baselines ( at the beginning of lines not the beginning of paragraph ) .

      123.png

        • 1. Re: GREP code
          [Jongware] Most Valuable Participant

          No. GREP is not aware of individual lines.

           

          To do something with lines, you need a script.

          2 people found this helpful
          • 2. Re: GREP code
            thaero17058 Level 1

            Thank you

            • 3. Re: GREP code
              Obi-wan Kenobi Adobe Community Professional

              Hi,

               

              Only by curiosity, what do you wanna do?

               

              (^/)

              • 4. Re: GREP code
                Obi-wan Kenobi Adobe Community Professional

                Aha! Now moderators can mark as correct all marks of politeness! Cool!

                 

                … [just immediately for comment and explanations later] It can be done with Grep, without script, in 1 click!

                Of course, hyphenation prohibited! 

                 

                Capture d’écran 2017-03-26 à 15.02.34.png

                 

                (^/) 

                • 5. Re: GREP code
                  thaero17058 Level 1

                  Hi

                  This is example : i want the GREP to find the word ( بن ) in this Arabic text if this word located at the beginning of line ( not beginning of paragraph )>>>> them i may replace the text or apply a character style on it ...  :

                  123456.png

                   

                  I know how to make a word boundary in GREP but i do not find GREP code to find this word at the beginning of lines .

                  I know  that : script can do this but , are there GREP code to do this .

                  • 6. Re: GREP code
                    Zaid Al Hilali Adobe Community Professional

                    I would use Find Text not GREP in this case to find بن where ever it may be, and apply a character style right from the Change format section.

                    Screen-Shot-2017-03-27-at-9.21.01-AM.jpg

                    • 7. Re: GREP code
                      thaero17058 Level 1

                      Hi

                      But i want to change word ( بن ) only if it's at the beginning of line ....

                      • 8. Re: GREP code
                        Obi-wan Kenobi Adobe Community Professional

                        … So, let's go! 

                         

                        Deal:

                        Let's find my name "Obi-wan Kenobi" [ "Ben", for friends! … ] ONLY if at the beginning of a line and let's apply "Obi-wan Kenobi CharStyle" to it!

                         

                        As I said [post#4] … with Grep, without script and in 1 click! 

                         

                        Capture d’écran 2017-03-27 à 15.51.35.png

                         

                        In the text, we have 8 mentions! To make it more visible for you, I've applied to my name a condition "Obi-wan Kenobi Condition" (blue underlining).

                         

                        Capture d’écran 2017-03-27 à 15.52.10.png

                         

                        … But we only want the 4 ones on the left side!

                         

                        To play this game, we need to play with "lines"!

                         

                        I totally agree with Jongware! It's not the play area of Grep! … But, all kids love to play in sandboxes! 

                         

                        The trick is to "get lines"!

                         

                        Capture d’écran 2017-03-27 à 15.52.43.png

                        Capture d’écran 2017-03-27 à 15.57.48.png

                         

                        … So, just 2 simple regex:

                         

                        Capture d’écran 2017-03-27 à 16.08.43.png

                        Capture d’écran 2017-03-27 à 16.08.24.png

                         

                        And a Multi-Find/change* set:

                         

                        Capture d’écran 2017-03-27 à 16.07.13.png

                         

                        [ * Great thanks to our friend Martinho da Gloria for this awesome plugin!  ]

                         

                        Done!

                         

                        Capture d’écran 2017-03-27 à 16.08.04.png

                         

                        (^/)

                        2 people found this helpful
                        • 9. Re: GREP code
                          Zaid Al Hilali Adobe Community Professional

                          Amazing Obi-wan, a real Jedi master you are!

                          • 10. Re: GREP code
                            Obi-wan Kenobi Adobe Community Professional

                            Pour les "grognons"! 

                             

                            app.findGrepPreferences = app.changeGrepPreferences = null;    
                            app.findGrepPreferences.findWhat = "Obi-wan Kenobi";
                            myFound = app.activeDocument.findGrep();
                            var F = myFound.length,  s = String("Obi-wan Kenobi").length;
                            for ( var f = 0; f < F; f++ )  if ( myFound[f].contents == myFound[f].lines[0].characters.itemByRange(0, s-1).contents )  myFound[f].appliedCharacterStyle = "Obi-wan Kenobi CharStyle";
                            app.findGrepPreferences = null;
                            

                             

                            Version courte !

                             

                            (^/)

                            2 people found this helpful
                            • 11. Re: GREP code
                              Obi-wan Kenobi Adobe Community Professional

                              Pour les "très-grognons, qui chercheraient seulement le premier mot de chaque ligne"! 

                               

                              var myWords = app.activeDocument.stories.everyItem().paragraphs.everyItem().lines.everyItem().words[0].getElements(),  W = myWords.length;
                              for ( var w = 0; w < W; w++ ) myWords[w].appliedCharacterStyle = "Red";
                              

                               

                              Version bikini !

                               

                              (^/)

                              2 people found this helpful