11 Replies Latest reply on Mar 20, 2015 5:52 AM by Peter Spier

    Grep Apostrophe

    scs38088219

      Hello!

       

      I would like to find wrong right single quotation marks instead of apostrophes using Grep.

       

      So far I could only find the respective words with this code:

      ('\w+')|(\w+'\w+)|(\w+')|('\w+)


      However, now I would like to replace the wrong right single quotation marks

      with apostrophes. What do I need to write in the replacement line to do so?


      So far it replaces the word with my grep code so is clearly going wrong.



      Thanks for any help/clues!


        • 1. Re: Grep Apostrophe
          vladan saveljic Level 4

          Hi,

          try this grep code.

           

          find:

          (?<=[\l\u])~](?=[\l\u])

           

          change:

          ~'

           

          Schermata 2015-03-18 alle 14.19.18.png

          • 2. Re: Grep Apostrophe
            Peter Spier Most Valuable Participant (Moderator)

            the problem is that there is no way to differentiate between a quotation that ends in an "s" and a plural possessive, such as girls' or boys' bicycles, so your grep misses a lot of potential cases.

            • 3. Re: Grep Apostrophe
              vladan saveljic Level 4

              Hi P Spier,

              you're right if text is in English (or language with similar rules).

              for example in italian or spanish there isn't this kind of problem.

              Therefor scs38088219 had to tell us which language he uses in his file

              • 4. Re: Grep Apostrophe
                scs38088219 Level 1

                Hi both,

                 

                thanks for help and also outlining the issues with this.

                 

                Unfortunately, I am working as a german speaker in an english country thus I would like to find the other cases as well.

                 

                Any idea how i would need to change my grep then to find all cases? It is likely that there are more abbreviations such as don't, isn't etc.

                than plural possessives, but it would be great to tackle all of them.

                 

                Thanks very much!

                • 5. Re: Grep Apostrophe
                  vladan saveljic Level 4

                  hi,

                  well, try this grep

                   

                  find:

                  (?<=[\l\u])~](?=[\l\u][\l\u]+)

                   

                  at least two letters after quotation mark

                   

                  change

                   

                  ~'

                  • 6. Re: Grep Apostrophe
                    Peter Spier Most Valuable Participant (Moderator)

                    I don't think there is ANY GREP solution that will differentiate the plural possessives from the quotes, so you probably need to do this in two steps.

                     

                    First would be to find all the cases where the apostrophe is followed by another letter, using Oscar's first expression, then look for (?<=s)~](?=[^\l\u]), which finds all the s' cases where there isn't a letter following, and step through manually to make the decision rather than using change all. There won't be a lot of cases, for sure, in most texts.

                    • 7. Re: Grep Apostrophe
                      scs38088219 Level 1

                      Thanks that is super helpful.

                       

                      I realised though that the GREP ignores words such as it's, etc. So with my initial grep I would be finding those words, but obviously when trying to change them it would replace them

                      with the GREP code instead.

                       

                      I am a newbie with GREP, so I would be grateful if someone could point the error out to me.

                       

                       

                      Cheers!

                      • 8. Re: Grep Apostrophe
                        Michael Witherell Adobe Community Professional

                        Try running my FindChangebyListPLUS. It has a couple of GREP searches built-in to it that clean up many ditto/quote mark/apostrophe situations:

                         

                        http://trainingonsite.com/panels-epubs-scripts/view_document/6-findchangebylistplus-javasc ript.html

                         

                        Mike in Maryland

                        • 9. Re: Grep Apostrophe
                          Peter Spier Most Valuable Participant (Moderator)

                          I realised though that the GREP ignores words such as it's, etc. So with my initial grep I would be finding those words, but obviously when trying to change them it would replace them

                          with the GREP code instead.

                          I think you might have misunderstood me. You need to do two complete steps. First, use Oscar's first GREP search and replace to find all instances where the apostrophe is followed by an upper of lower case letter and replace with ~'. After that step is complete, run a new search for (?<=s)~](?=[^\l\u]) and replace with ~', but in this case you must use Find, then either Find Next or Change and Find, depending on your decision of whether it is a possessive or a quotation, to step through and examine each case rather than using change all as you could in the first search

                          • 10. Re: Grep Apostrophe
                            scs38088219 Level 1

                            Hi,

                             

                            I did run both versions, however I have these issues:

                             

                            Oscars version leaves out:

                            "It’s". "There's"

                             

                            Your version only finds cases such as: others', fans'

                             

                            So it only does the job partly. Thats why I was wondering how I can avoid doing only half of it. "It's" is rather common for instance.

                             

                            @Michael

                            Many thanks for suggesting that, but I would rather use manual solutions.

                            • 11. Re: Grep Apostrophe
                              Peter Spier Most Valuable Participant (Moderator)

                              You must use Oscar's first version: (?<=[\l\u])~](?=[\l\u]) and it will find any instance between two alphabetic characters. If it is failing, then there is something else wrong with your search parameters -- possibly you have limited the scope in some way.