13 Replies Latest reply: Apr 8, 2011 4:18 PM by P Spier RSS

    Search & Replace (GREP?)

    peterpica Community Member

      Is it possible to search for multiple character strings at one time and simultaneously replace them with other multiple character strings?

       

      For example, if I have upper and lower case acronyms (Pcc, Rs-3, Prr, Rdg, etc...) sprinkled throughout a doc, is there a way of doing a single search and replace that would replace these with PCC, RS-3, PRR, RDG, etc. throughout the doc?sample.jpg

       

      I'm doing these in separate search & replace actions now and thought there might be some way (grep?) of streamlining it to minimize the steps.

       

      Thanks.

        • 1. Re: Search & Replace (GREP?)
          [Jongware] Community Member

          You can certainly search for more than one string, but you can only replace it with one and the same text (although you can "copy" parts of the found text).

           

          One option is to search for all of your lowercase strings and apply only some formatting, as a local override or with a character style. And I was thinking of "All Capitals" here.

           

          Another option could be to make good use of the FindChangeByList script that comes installed by default with your InDesign.

          • 2. Re: Search & Replace (GREP?)
            peterpica Community Member

            <One option is to search for all of your lowercase strings and apply only some formatting, as a local override or with a character style. And I was thinking of "All Capitals" here.>

             

            This sounds interesting... how to implement in one search? I'm doing that now but one acronym at a time.

             

            I wrote to a developer regarding this and requested a quotation for writing a script for it... $500 estimated; his quote included a "tad more functionality" than just what I've described tho. I can't hack that amount for something like this... would take several years to recoup the cost.

            • 3. Re: Search & Replace (GREP?)
              John Hawkinson CommunityMVP

              Again, have you looked at FindChangeByList that comes free with InDesign?

              • 4. Re: Search & Replace (GREP?)
                peterpica Community Member

                Yes, John. It munged up the text block something awful.

                 

                A friend wrote me a .jsx script that works great with an unlimited number of acronyms doable in one script.

                 

                Now I've only three steps... apply a "smart styles" to the imported xls.txt text block, convert to ulc, then run the new .jsx script and voila. Best part is I can add to the .jsx list myself.

                 

                Thanks anyway.

                • 5. Re: Search & Replace (GREP?)
                  rantingrick

                  Do you have a list of acronyms or a 100% reliable pattern?

                   

                  In that case, you can just grep for the acronyms and have Find Format as Normal then set the Change Format to All Caps. Then just grep for

                   

                  \b(Nyc|Pcc|Sd-45)\b

                   

                  replace with

                  $1

                   

                  and the Find/Change format should take care of making it all caps.

                   

                  By the way, I don't know whether ID grep recognizes the zero-width word border character (\b), but you could delimit by whitespace as well like so

                   

                  (\s(Nyc|Pcc|Sd-45)\s)

                   

                  And that should work too if there is actual whitespace

                  • 6. Re: Search & Replace (GREP?)
                    peterpica Community Member

                    thanks... GREP is not my forté! Anything with code scares the stuff out of me.

                     

                    I'll give that a try; however, the .js that Scott Selberg (Action Forge fame) did for me works quite well.

                    • 7. Re: Search & Replace (GREP?)
                      [Jongware] Community Member

                      Ranting Rick (well, & Peter P. I guess),

                       

                      rantingrick wrote:

                       

                      Do you have a list of acronyms or a 100% reliable pattern?

                       

                      In that case, you can just grep for the acronyms and have Find Format as Normal then set the Change Format to All Caps. Then just grep for

                       

                      \b(Nyc|Pcc|Sd-45)\b

                       

                      replace with

                      $1

                       

                      Don't put anything in the Replace With. If you replace with formatting only, you don't need to "put back" the found text. That'll work way faster! (You still need the parentheses in the Search field, 'cause else the \b's will only attach to the first and last items.)

                       

                      Ah -- and if you do want to write out "the found text" (fer instance, because you add something before or after it), simply use $0 instead, and there is no need to worry about counting parens.

                      By the way, I don't know whether ID grep recognizes the zero-width word border character (\b), but you could delimit by whitespace as well like so

                       

                      (\s(Nyc|Pcc|Sd-45)\s)

                       

                      Yes, ID knows \b (Peter Kahrel once put forward that ID uses boost for its GREP, and after some comparisons I think I concur).

                      Your whitespace-boundary ought to work just fine for Peter P.'s document, but only because his items are bounded by white space But it's not equal to "entire words only", as its Plain Text equivalent is called. In more general cases, I'd recommend to use \b before and after instead.

                      • 8. Re: Search & Replace (GREP?)
                        peterpica Community Member

                        Gosh I wish you guys would speak in POE!

                        • 9. Re: Search & Replace (GREP?)
                          [Jongware] Community Member

                          I'm guessing it's not Edgar Allan you are referring to, so what POE would that be?

                           

                          As for GREP: read Mike Witherell's column Adventures in GREP for a brief introduction and a lot of useful examples, and, if that tickles the right nerves, follow his advice and order Peter Kahrel's eBook GREP in InDesign. For under a tenner you could do worse.

                          • 10. Re: Search & Replace (GREP?)
                            P Spier CommunityMVP

                            I think POE means Plain Old English, but I wouldn't swear to it, and I'm not sure what wasn't that could actually be translated.

                            • 11. Re: Search & Replace (GREP?)
                              peterpica Community Member

                              p (as in plain)   o (as in old)   e (as in English)

                               

                               

                               

                               

                              roflol&pimp2!

                              • 12. Re: Search & Replace (GREP?)
                                peterpica Community Member

                                I had my belly-full of code a generation ago when I worked with unix... we had the Bedford RTCS (real time composition system) that was THE 1st wysiwyg hardware/software combo out there, c. 1974 origin...in order to debug your pages, you had to go into the code.... UGH!

                                 

                                Was (and probably still is) the best way, but when there are viable options, why bother? I'm too old to relive the horrors (albeit accuracy) of code...

                                • 13. Re: Search & Replace (GREP?)
                                  peterpica Community Member

                                  Whoah! It's 7:25 e.s.t.--Time for the Phillies!

                                   

                                  GAME OVER MAN!