4 Replies Latest reply on Mar 19, 2013 11:08 AM by maxhodges0

    another GREP challenge!

    maxhodges0 Level 1

      OK given this source text

       

      Another two-grapheme kanji. The combination is visual (the @sun@ 日 is seen partly obscured by a @tree@ 木), but the meaning is abstract (^EAST^), so see this as a $rising$ sun and $visualize$ the idea of ^EAST^. Try to associate the image with a memorable sunrise from your own experience. An $on-yomi$ compound appears in the next entry.

       

      I can set SUN and TREE with this

      "\^(.+?)\^", "$1"

       

      And I get take get both EAST and EAST with this:

      "\@(.+?)\@", "$1"

       

      But this one only gets RISING but not VISUALIZE or ON-YOMI:

      "\$(.+?)\$", "$1"

       

      what am I doing wrong?

        • 1. Re: another GREP challenge!
          maxhodges0 Level 1

          This is odd. Maybe a bug in Indesign? The first two find all the occurances, but the final one stops after it finds the first one. Both in scripting and also with the GUI Find/Change dialog.

          • 2. Re: another GREP challenge!
            maxhodges0 Level 1

            found a workaround. If I just run the grep multiple times it will get them all

             

                    Private Sub AnnotationStyler(ByRef targetCell As InDesign.Cell, ByRef doc As InDesign.Document, ByRef app As InDesign.Application)

                        Dim mycharstyle As InDesign.CharacterStyle = doc.CharacterStyles.Item("[None]")

                        Dim myparastyle As InDesign.ParagraphStyle = doc.ParagraphStyles.Item("SK-comment")

             

                        app.ClearOverridesWhenApplyingStyle = True

                        For Each para As InDesign.Paragraph In targetCell.Paragraphs

                            para.AppliedCharacterStyle = mycharstyle

                            para.AppliedParagraphStyle = myparastyle

                        Next

                        ' style text wrapped in ^ as bold

                        FindChangeGREP(app, doc, targetCell, "SK-bold", "\^(.+?)\^", "$1")

             

                        ' style text wrapped in @ = smallcaps

                        FindChangeGREP(app, doc, targetCell, "SK-smallcaps", "\@(.+?)\@", "$1")

             

                        ' style text wrapped in $ as italic

                        FindChangeGREP(app, doc, targetCell, "SK-italic", "\$(.+?)\$", "$1")

                        FindChangeGREP(app, doc, targetCell, "SK-italic", "\$(.+?)\$", "$1")

                        FindChangeGREP(app, doc, targetCell, "SK-italic", "\$(.+?)\$", "$1")

             

                        FindChangeGREP(app, doc, targetCell, "pointinghand", "☞")

             

                    End Sub

             

             

                    Private Sub FindChangeGREP(ByRef app As InDesign.Application, ByRef doc As InDesign.Document, ByRef theCell As InDesign.Cell, ByVal CharacterStyle As String, ByVal FindWhat As String, ByVal changeTo As String)

                        Dim mycharstyle As InDesign.CharacterStyle = doc.CharacterStyles(CharacterStyle)

                        app.FindGrepPreferences = idNothingEnum.idNothing

                        app.ChangeGrepPreferences = idNothingEnum.idNothing

                        app.FindChangeGrepOptions.IncludeFootnotes = False

                        app.FindChangeGrepOptions.IncludeHiddenLayers = False

                        app.FindChangeGrepOptions.IncludeLockedLayersForFind = False

                        app.FindChangeGrepOptions.IncludeLockedStoriesForFind = False

                        app.FindChangeGrepOptions.IncludeMasterPages = False

                        app.ChangeGrepPreferences.AppliedCharacterStyle = mycharstyle

                        app.FindGrepPreferences.FindWhat = FindWhat

                        If changeTo <> "%" Then app.ChangeGrepPreferences.changeTo = changeTo

                        theCell.ChangeGrep()

                    End Sub

            1 person found this helpful
            • 3. Re: another GREP challenge!
              designmon79

              Hi,

               

              You can also put $ in character class [$]. Then it will gets RISING, VISUALIZE or ON-YOMI:

               

               

              Try this.

               

              "[$](.+?)[$]", "$1"

               

              Thanks,

              Mon

              • 4. Re: another GREP challenge!
                maxhodges0 Level 1

                that works! Thank you! can you explain why it works to me?! (why mine didn't work?)