16 Replies Latest reply on Aug 29, 2016 5:09 AM by Laubender

    Preserving and recalling with GREP

    sperry1975 Level 1

      Lets say I have a paragraph of text and at the bottom of the paragraph I have (text p.##) or something similar but always between (). How can I write an grep expression to search for anything between () and change the text to italics then leave all the rest as is? There's some way or expression that finds content between () which I can probably figure out on my own, but what I've been really searching for, without luck so far, is how to preserve or keep what you find and recall it or have it recalled for the replacement in a find and change grep expression. Any idea or links that would be helpful in figuring this all out.

        • 1. Re: Preserving and recalling with GREP
          Salah Fadlabi Level 5

          Try:

          (?<=\().*?(?=\))

          1 person found this helpful
          • 3. Re: Preserving and recalling with GREP
            sperry1975 Level 1

            (?<=\().*?(?=\)) works for find any text inside parentheses, but not including the parentheses. But if I use it to search the following paragraph it doesn't help find anything:

                 Сегодня нам, как народу Божьему нужно всецело, с серьезной молитвой посвятить себя работе, которая ведется от нашего имени в небесном святилище. Мы живем в прообразный День искупления, и Бог многого ожидает от тех, кто относит себя к Его церкви остатка. «В то время как происходит следственный суд на небесах, когда грехи кающихся грешников удаляются из святилища, среди народа Божьего на земле должна произойти особая работа очищения и оставления греха» (Великая борьба, с. 425).

            What I'm wanting located is (Великая борьба, с. 425).

            What I'm wanting to replaced it with is (Великая борьба, с. 425).

            • 4. Re: Preserving and recalling with GREP
              Laubender Adobe Community Professional & MVP

              Hi Obi-wan,

              could you discuss your GREP a bit?

               

              For example:

              Why do you use \ in the character class: [^\(]* ?

              Why not simply doing it this like: [^(]* ?

               

              That question is academic, since results should be the same.

               

              Another observation:

              I tried to get the same results using \K instead of the Positive Lookbehind (?<=), but it seems, that \K has a different effect here.
              Seems that \K sometimes cannot be used as a full substitute for a Positive Lookbehind (?<=) .

               

              \(\K

              as far as I understood \K before this use case here, \K should do the same as:

              (?<=\()

               

              But the character class following would be ignored with \K (?! I'm not sure what eaxctly happens here ?!), but not with the usual Positive Lookbehind:

               

              \(\K[^\(]*.+p\.\h+\d+(?=\)$)

              versus:

              (?<=\()[^\(]*.+p\.\h+\d+(?=\)$)

               

              So I was wrong on my assumption.

               

              Screenshot example (edited):

               

              K-NO-SUBSTITUTE-for-Positive-Lookbehind-2.png

               

              Best,

              Uwe

              • 5. Re: Preserving and recalling with GREP
                Obi-wan Kenobi Adobe Community Professional

                … So, try:

                 

                (?<=\()[^(]*(?=,\hc\.\h\d+?\)\.$)

                 

                (^/) 

                • 6. Re: Preserving and recalling with GREP
                  Salah Fadlabi Level 5

                  sperry1975 wrote:

                   

                  (?<=\().*?(?=\)) works for find any text inside parentheses, but not including the parentheses. But if I use it to search the following paragraph it doesn't help find anything:

                   

                  What I'm wanting located is (Великая борьба, с. 425).

                  What I'm wanting to replaced it with is (Великая борьба, с. 425).

                  Tried here no problem

                  3.png

                   

                  If you want including the parentheses try:

                  \(.*?\)

                  • 7. Re: Preserving and recalling with GREP
                    Obi-wan Kenobi Adobe Community Professional

                    Hi Uwe,

                     

                    About:

                     

                    Why do you use \ in the character class: [^\(]* ?

                     

                    If the 2 are OK, I've used [^(] !!  [see more!]

                     

                    Your problem is not \K [it works correctly], but your new error in the grep code!

                    I've written:

                     

                    (?<=\()[^(]*p\.\h\d+?(?=\)$)

                     

                    … not:

                     

                    (?<=\()[^\(]*.+p\.\h+\d+(?=\)$)

                     

                    .+ is the reason! Including it, [^(]* looses all effect! I use it to prevent the case where there's no text!

                    + is not useful if the typo corrections has been well done! ;-)

                     

                    (^/)

                    • 8. Re: Preserving and recalling with GREP
                      sperry1975 Level 1

                      I don't want to include the parentheses I want to exclude them, but I don't want to include the characters after the comma or period in some other cases.

                      • 9. Re: Preserving and recalling with GREP
                        Laubender Adobe Community Professional & MVP

                        Hi sperry1975,

                        I copied your text example to my InDesign document and tested with Obi-Wan's GREP to isolate the text inside the last bracket.
                        First I had no success. Then I saw that с is not c, but a different character code.

                         

                        I had success with:

                        (?<=\()[^(]*,(?=\h\x{441}\.\h\d+?\)\.$)

                         

                        c-is-unlike-c-GREP.png

                         

                        Best,
                        Uwe

                        • 10. Re: Preserving and recalling with GREP
                          Salah Fadlabi Level 5

                          Also you can do it with nested style:

                          Create a character style with italic

                          4.png

                          • 11. Re: Preserving and recalling with GREP
                            Laubender Adobe Community Professional & MVP

                            Obi-wan Kenobi wrote:

                             

                            Hi Uwe,

                             

                            About:

                             

                            Why do you use \ in the character class: [^\(]* ?

                             

                            If the 2 are OK, I've used [^(] !! [see more!]

                             

                            Your problem is not \K [it works correctly], but your new error in the grep code!

                            I've written:

                             

                            (?<=\()[^(]*p\.\h\d+?(?=\)$)

                             

                            … not:

                             

                            (?<=\()[^\(]*.+p\.\h+\d+(?=\)$)

                             

                            .+ is the reason!

                            + is not useful if the typo corrections has been well done! ;-)

                             

                            (^/)

                            Oh boy, I should do no GREP Styles in the morning without my first coffee.

                            Thank you,
                            Uwe

                            • 12. Re: Preserving and recalling with GREP
                              Obi-wan Kenobi Adobe Community Professional

                              Salah, dangerous if others parenthesis! 

                              • 13. Re: Preserving and recalling with GREP
                                Obi-wan Kenobi Adobe Community Professional

                                Yeap! 

                                 

                                Coffee will always be a partisan of The Force!

                                 

                                MTFBWY!

                                (^/)

                                • 14. Re: Preserving and recalling with GREP
                                  Obi-wan Kenobi Adobe Community Professional

                                  Uwe,

                                   

                                  The comma is not a part of the Italic text, it's a separator followed by the page number!

                                  So, it needs to be included in the lookahead!

                                   

                                  (^/) 

                                  • 15. Re: Preserving and recalling with GREP
                                    Laubender Adobe Community Professional & MVP

                                    Hi Obi-wan,

                                    don't think so:

                                     

                                    sperry1975 wrote:

                                    What I'm wanting located is (Великая борьба, с. 425).

                                    What I'm wanting to replaced it with is (Великая борьба, с. 425).

                                     

                                    sperry1975 wrote:

                                    I don't want to include the parentheses I want to exclude them, but I don't want to include the characters after the comma or period in some other cases.

                                     

                                    So…
                                    Perhaps we even need a character class for including a comma, a period (maybe something else?)
                                    That's a bit unclear to me.

                                     

                                    Regards,
                                    Uwe

                                    • 16. Re: Preserving and recalling with GREP
                                      Laubender Adobe Community Professional & MVP

                                      So i think sperry1975 could live with the following GREP Style:

                                       

                                      (?<=\()[^(]*[,.](?=\h[\x{441}\x{421}]\.\h\d+?\)\.$)

                                       

                                      Now, it could be either a comma or a period.
                                      And if a period we need another character class that would include not only:

                                       

                                      с
                                      CYRILLIC SMALL LETTER S

                                      \x{441}

                                       

                                      but also:

                                       

                                      С

                                      CYRILLIC CAPITAL LETTER S

                                      \x{421}

                                       

                                      After a period one would start always with a capital letter.

                                       

                                      TwoCharacterClassesAdded-GREP.png

                                       

                                      Regards,
                                      Uwe