6 Replies Latest reply on Apr 14, 2013 4:08 AM by Eleivana07

    Using Grep to change case in 2nd of a two word string

    Eleivana07 Level 1

      Hello all

      I found out after completing my project that I had made a big boo boo.

      I have multiple (hundreds) 2 word botanical names of plants which are all located after a certain heading style throughout 400 pages.

      The first word in this name is capitalized already. Thats ok. But the second word needs to start with a lower case letter ( Instead of a capital letter like it has now).

      All the 2 word names are seperated by commas.

      Any ideas?

       

      Thanks in advance

      Lauren

        • 1. Re: Using Grep to change case in 2nd of a two word string
          Peter Kahrel Adobe Community Professional & MVP

          Maybe show us some examples.

          • 2. Re: Using Grep to change case in 2nd of a two word string
            Eleivana07 Level 1

            Hi Peter

            OK

            Example:

             

            Plant Species: Crambe Abyssinica

            Plant Species Synonyms: Brassica Nigra Var. Abyssinica, Crambe Hispanica, Crambe Kilimandscharica

             

            The headings Plant Species and Plant Species Synonyms are in a character style "Red Bold"

            These plant names are all styled with a character style called "Index"

             

            The first heading Plant Species usually only has one 2 part binomial name. In this case the second word 'Abyssinica' needs to start with lower case ( I forgot about these when I posted my request)

             

            The second heading 'Plant Species Synonyms' usually has more than two 2 word names seperated by commas

            There are of coarse some plants which have no plant species synonyms.

             

            I was able to create an awesome index with scripting help from this forum (Actually it was you Peter K. with some great help from Peter S. !!)

            In order to be 'correct' though these second words of the plant binomial names need to be lowercase.

            These headings and format repeat hundreds of times

            Does this help clarify things a bit?

            Thanks Peter

            • 3. Re: Using Grep to change case in 2nd of a two word string
              Peter Kahrel Adobe Community Professional & MVP

              Try this:

               

              app.findGrepPreferences = null;
              app.findGrepPreferences.findWhat = /(?<=\u)\l+\s.+/.source;
              app.findGrepPreferences.appliedCharacterStyle = 'Index';
              found = app.documents[0].findGrep();
              for (i = 0; i < found.length; i++){
                  found[i].contents = found[i].contents.toLowerCase();
              }
              

               

              which converts to lowercase everything following the first capital, so Brassica Nigra Var. Abyssinica will be converted to Brassica nigra var. abyssinica. If that's not correct you should check index entries consisting of more that two words. You can do that using this Grep: .\s.+?\s.

               

              Peter

              • 4. Re: Using Grep to change case in 2nd of a two word string
                Eleivana07 Level 1

                Hi Peter

                Not to be dense but is this a script? Looks like one so wouldn't I just paste it into Adobe ExendScript toolkit, give it a name, save and then run it?

                I think thats what I did with the last script I got from this forum

                Ok did the above

                Ran it and got Error 14: No matching closing brace found.

                 

                If this is a GREP expression I am not sure how to work it.

                Could you clarify the process a bit?

                • 5. Re: Using Grep to change case in 2nd of a two word string
                  Peter Kahrel Adobe Community Professional & MVP

                  Lauren,

                  Yes, it's a script. Sorry, I thought that since you had used scripts before I needn't explain, and that turned out to be correct, because you did the right thing

                   

                  "No matching closing brace found" almost certainly means that you forgot the copy the last line, which has just the closing brace in it. Please add that and try again.

                   

                  The script looks for all text formatted with the Indexcharacter style and which contains two or more words. It excludes the beginning capital:

                   

                  (?<=\u)   is a positive lookbehind which means 'match things following a capital, not the capital itself'

                  \l+            one or more lower-case letters

                  \s             a space

                  .+             one or more characters

                   

                  I think that \l+ should be \l.+, by the way, so please replace the second line of the script with this one:

                   

                  app.findGrepPreferences.findWhat = /(?<=\u)\l.+\s.+/.source;

                   

                  Peter

                  • 6. Re: Using Grep to change case in 2nd of a two word string
                    Eleivana07 Level 1

                    OK Peter

                    Once again you are AMAZING!! This last word needs to be sung falsetto.

                    Worked great-quickly silently. Like magic.

                    Saved me hours and hours of work.

                    At first I wasn't sure it did anything as I was almost expecting the cursor to jump to each word it changed but it just happened instantaneously.

                    Thanks again and I hope this helps someone else too.

                     

                    Lauren