4 Replies Latest reply on Aug 10, 2011 5:46 AM by Eli.Shklovsky

    Greps

    enzoconti

      I am interested in learning how to use Grep styles, but can't even to begin to understand how to build those codes. I've had a bit of a play inside the paragraph styles to search for phone numbers eg. (03) 3433 5454. Can anybody explain how to do this?

        • 1. Re: Greps
          John Hawkinson Level 5

          Well, there are a lot of differnet ways to represent phone numbers, so what exactly do you want?

           

          For instance: Left paren followed by 2 digits followed by right paren followed by a space followed by 4 digits followed by a space folllowed by 4 digits? That would be /(\d\d) \d\d\d\d \d\d\d\d/ or written more compactly, /\d{2} \d{4} \d{4}/. (I surround my regexps in /slashes/ for historical reasons. You're not supposed to type the forward slashes, but you certainly must type the baskslashes: \)

           

          But as a practical matter, if you ever write phone numbers differently, especially international ones, then these will not work.

          So it can get very complex very fast.

           

          Also, phone numbers are the second example in the manual. Did you look?: GREP search examples

          1 person found this helpful
          • 2. Re: Greps
            enzoconti Level 1

            Thanks John, I will go and have another look. I guess I have to learn the "language" of Greps, it's just at first glance, all those terms and codes look totally foreign. I don't think it's very intuitive, or maybe it's just me?

            • 3. Re: Greps
              John Hawkinson Level 5

              It's not intuitive, nope. It is...not designed to be.

              You may need to reset your expectations.

               

              On the other hand, "\d" stands for "digit." It could be worse.

               

              But yes, you should expect to have the list of codes in front of you

              while you work with these things.

              • 4. Re: Greps
                Eli.Shklovsky

                another thing to remember while scripting greps, you should reset the greps at the begining and at the end :

                 

                //Reset at the beginning:

                app.findGrepPreferences = NothingEnum.nothing;

                app.changeGrepPreferences = NothingEnum.nothing;

                 

                app.findGrepPreferences.findWhat = "([\\l\\u])";

                app.findGrepPreferences.appliedParagraphStyle= "findStyle";

                app.changeGrepPreferences.appliedCharacterStyle = "replaceStyle";

                myObj.changeGrep(true);

                 

                //Reset at the End:

                app.findGrepPreferences = NothingEnum.nothing;

                app.changeGrepPreferences = NothingEnum.nothing;