10 Replies Latest reply on Dec 13, 2016 10:04 AM by Obi-wan Kenobi

    GREP help

    crizlo Level 1

      I need help creating a GREP expression that will change the formatting of the first two words of a paragraph including a number that may or may not be following (e.g. Executive Director, Executive Director 2).


      Any help would be appreciated.


      Thanks much.

        • 1. Re: GREP help
          Michael Witherell Adobe Community Professional


          • 2. Re: GREP help
            crizlo Level 1

            Thanks Michael. It works perfectly, and it seems so easy, now that I see your formula.


            Sure appreciate your help.

            • 3. Re: GREP help
              Obi-wan Kenobi Level 5



              Not correct!


              Capture d’écran 2016-12-13 à 10.35.25.png







              • 4. Re: GREP help
                crizlo Level 1

                Thanks for your reply Obi-Wan. I tested your GREP solution as well, and it also worked as expected.


                Both your solution and Michael's solution behave the same (at least for my particular needs).


                I'm eager to better understand GREP, so perhaps you could elaborate on why you feel your answer is correct, yet Michael's is not?


                Thanks much.

                • 5. Re: GREP help
                  Obi-wan Kenobi Level 5

                  Of course, Michael's code seems to work because his way is just enough in your case but, as I show, his code includes the "space" after the two words if no number (+ a space before) after them!

                  It could be problematic if you really need to find these two words and only them!

                  For instance, to make an index. In this case, the entry would include this "space"


                  If you wanna play with Grep, keep in mind that you'll need to be "precise"!

                  In any case, by accepting it, be aware of your "vagueness" and its possible consequences!


                  Another writing [I like!]:





                  1 person found this helpful
                  • 6. Re: GREP help
                    Michael Witherell Adobe Community Professional

                    Vagueness is kind of nice; you should try it sometime!


                    Obi-wan, in your GREP, I am not familiar with \H+. Does that mean "anything NOT a horizontal space one or more times", effectively a word? And what does h(?1) mean? Does that mean ONLY one space? And what does the third grouping mean?

                    • 7. Re: GREP help
                      Obi-wan Kenobi Level 5

                      Hi Michael,


                      To be really precise, we would use this:




                      What does it mean?



                      --> Beginning of para


                      --> any group of letters (no space, no number) -- see below why this writing is better!


                      --> horizontal space (12 kinds of space + tab)


                      --> that means the same kind of group (delimited by parenthesis) than the first one, so: ([\u\l]+)


                      --> interesting writing: '(?> … )' is an "unbreakable" entity! with the "?" behind it, we means: "exist or not".

                      the targetted unbreakable group is: '\h\d+'

                      Using this code will avoid the problem you have with your code.


                      So, my code has 4 parts: a word + a space + a word (+ in option: a space + a number)


                      Using ([\u\l]+) will avoid to take in account:  "Director 2" at a para beginning.




                      I like precision but, I repeat, your code could be enough here! 



                      • 8. Re: GREP help
                        Michael Witherell Adobe Community Professional

                        Obi-wan, thank you for that instruction. I feel a bit smarter, now. My Vague-O-Meter needle has swung a bit to the right!

                        • 9. Re: GREP help
                          crizlo Level 1

                          Obi-wan, thanks for the detailed breakdown and explanation. We all appreciate your "precision" and expertise.

                          • 10. Re: GREP help
                            Obi-wan Kenobi Level 5

                            End of your training! 



                            Capture d’écran 2016-12-13 à 18.54.38.png


                            Less risky!   ^(([\u\l-])+)\h(?1)(?>\h\d+(?!\H))?  …but really less readable! 


                            Capture d’écran 2016-12-13 à 18.54.51.png


                            … Just for fun!