10 Replies Latest reply on Dec 18, 2015 1:23 AM by Obi-wan Kenobi

    Regex

    Eyenan.

      Hi,

                I want to get <tag>.....</tag> contents using GREP. Please refer screenshot.

       

                There is two occurrence found. If I'm using this GREP, then I'm getting 2nd occurrence only.

       

                The first occurrence won't get because of inline table present.

       

                Please do the needful on this.  Thanks...Regex.jpg

        • 1. Re: Regex
          Marc Autret Level 4

          Hi Eyenan,

           

          Sorry, I don't know the answer (but I'd like to!)

           

          To my knowledge GREP cannot pass through the table marker (U+0016), even in (?s) mode. Unlike the Text search mode—which can somehow capture a table using <0016>—the GREP metacharacter \x{16} does not work at all, and the generic dot always fails to grab such element.

           

          Maybe GREP gurus know a workaround…

           

          @+,

          Marc

          • 3. Re: Regex
            Peter Kahrel Adobe Community Professional & MVP

            As Marc said, you can't get around the table. Even something like <tag>[^<]+ stops at the table, which looks unusual. If in your document you select some text so that the selection includes the first tag pair and the table, then this:

             

            app.selection[0].contents.match(/<tag>[^<]+<\/tag>/)

             

            returns this:

             

            <tag>Feribea . . . inimus.TSolorerum . . .sundanimus.</tag>

             

            where T is the table, \x16.

             

            (Footnote markers have a similar problem, but at least you can get past them in a rather convoluted way, but that doesn't work for tables.)

             

            The only work-around I found is this:

             

            app.findGrepPreferences = null;
            app.findGrepPreferences.findWhat = '</?tag>';
            tags = app.documents[0].findGrep();
            
            for (i = 0; i < tags.length; i=i+2) {
               tagrange = tags[i].parentStory.characters.itemByRange (tags[i], tags[i+1].characters[-1]);
               // do something with the tag range
            }
            

             

            Peter

            • 4. Re: Regex
              Peter Kahrel Adobe Community Professional & MVP

              I had completely forgotten about that thread, Harbs.

               

              P.

              • 5. Re: Regex
                Obi-wan Kenobi Adobe Community Professional

                Hi,

                 

                If the tables annoy you, make them disappear! 

                … To do that, you could need a light-saber!!

                 

                MTFBWY!  ^/

                • 6. Re: Regex
                  david_p Level 1

                  Depending on what you're ultimately trying to do, a workaround would be to export the story as tagged text and perform any find/change operations using a text editor that supports regular expressions, then re-import into InDesign.

                  • 7. Re: Regex
                    Eyenan. Level 1

                    Hi Marc,

                     

                         Thanks for your comment.

                        

                         I learned text search mode from you....

                    • 8. Re: Regex
                      Eyenan. Level 1

                      Hi Harbs,

                       

                           Thanks for your links.

                      • 9. Re: Regex
                        Eyenan. Level 1

                        Hi Peter,

                            

                             Thank you very much for your valuable comments.

                        • 10. Re: Regex
                          Obi-wan Kenobi Adobe Community Professional

                          Hi,

                           

                          Comment on my previous post: what I mean it that if you search tables (using text research based on <0016>) and replace by a condition that you mask then, you can easily manipulate the tags [using your grep code that is totally relevant], as you have no table!