8 Replies Latest reply on Dec 17, 2016 6:32 AM by Obi-wan Kenobi

    GREP some, not all, parenthetical content

    DesignerBob13013 Level 1

      Hi everyone.

      I have a quick and wonderful GREP expression to apply an italicizing character style to parenthesis and the copy that falls within — 

       

      \(.+?\)

       

      Here's the kicker. Visually, I don't want to Italicize the content and parenthesis when it is an acronym.

       

      Division of Motor Vehicle (DMV)  <-- no italics

      Book title (extra detail)  <--- italics

       

      I'm guessing the answer involves  \u\u+ which looks for two or more capital letters in a row.

       

      So, it should, italicize parenthesis and content within, but not when the parenthetical material is all caps.

       

      Any ideas? Thanks everyone.

      -Bob

        • 1. Re: GREP some, not all, parenthetical content
          winterm Level 4

          Try this:

          \(.+[^\u]\)

           

          it finds all occurrences except first here:

          Division of Motor Vehicle (DMV)  <-- no italics

          Book title (extra detail)  <--- italics

          Book title (Extra Detail)  <--- italics

          Book title (Division of Motor Vehicle)  <--- italics

          • 2. Re: GREP some, not all, parenthetical content
            DesignerBob13013 Level 1

            PERFECT! Thank you Winterm.

            • 3. Re: GREP some, not all, parenthetical content
              Obi-wan Kenobi Adobe Community Professional

              Sorry! Not correct.

               

              Book title (Division of Motor Vehicle, DMV) 

               

              \((?!\u+\)).+?\)

               

              (^/) 

              1 person found this helpful
              • 4. Re: GREP some, not all, parenthetical content
                winterm Level 4

                Hey, Obi-wan, it's not a bullet-proof solution for tutorial, after all.

                when it covers real-world OP's request, then it's enough...

                why search for things that never happen?

                "Less is More"

                • 5. Re: GREP some, not all, parenthetical content
                  pixxxel schubser Level 5

                  Only a bullet-proof grep with no false positive and no false negative hits is a good grep

                   

                   

                  winterm,

                  keep cool. It's only a big sandbox.

                  btw please replace the + in your own grep in post #1 with +? for this following case which is never happens:

                  Book title (Division of Motor Vehicle)  Book title (extra detail)

                   

                  Friendly regards

                   

                  • 6. Re: GREP some, not all, parenthetical content
                    Obi-wan Kenobi Adobe Community Professional

                    Keep Cool!  Do you really understand what you mean with:

                     

                    \(.+[^\u]\)

                     

                    You only say that you italicize all content between parenthesis whose last char is not a capital!!  [pixxxel ( )  is totally right about +?]

                     

                    So:

                     

                    (in US)

                     

                    … won't be taken by your code! … but not:

                     

                    (in Fr)

                     

                    ……

                     

                    When I read Bob's question:

                     

                    … "I don't want to Italicize the content and parenthesis when it is an acronym."

                     

                    That simply means:

                     

                    \((?!\u+\)).+?\)

                     

                    Bob wants to italicize all content between parenthesis only if this content is not a group of capitals!

                    … so, only if the "entering" parenthesis is not followed by capitals and a "closing" parenthesis!!

                     

                     

                    (^/) 

                    • 7. Re: GREP some, not all, parenthetical content
                      winterm Level 4

                      Do you really understand what you mean...

                      Yes, I do. Agreed, one may find such approach rather strange, but it works on OP samples. I listed cases it covers - don't you find it fair enough? That said, I have learned not answer the questions I wasn't asked. Your life experience may be different.

                       

                      So: (in US) … won't be taken by your code!

                      So what? It's not here in the samples OP provided. I guess it's possible to invent scenarios which even Your smart code won't cover - then you'll need even more gorgeous one, and that's no surprise.

                      Pixxxel's addition is useful to restrict the GREP greediness. Seems like it's not the case in OP's text, so I omitted it. Would there be any harm of adding it? No!

                      Your codes cover much wider area, still aren't something worth to save for future reference. It's still kind of "use it once and throw away".

                      IMHO, nobody's really right or wrong here, it's just a matter of POV, so I find this further discussion rather pointless.

                      Peace and Merry Christmas to everyone

                      • 8. Re: GREP some, not all, parenthetical content
                        Obi-wan Kenobi Adobe Community Professional

                        Aha!

                         

                        It's very easy to self-define the cases!

                         

                        "It works in this case, this one … and this other one! …

                        If it doesn't work in that case, it's not a problem … because I don't care of it!!"

                         

                        "Italicize all text between parenthesis except acronyms" was the question I've read.

                         

                        Your interpretation is not mine!

                         

                        Sorry to have contradicted you, but I don't think like you and I don't use Grep in your way!!

                         

                        (^/)