4 Replies Latest reply on Feb 12, 2013 7:01 AM by Vamitul

    (JS) Grep problems

    Vamitul Level 4

      Hello!

      I have a problem when using a series of find/change greps.

      A bit of introduction. We are using a set of custom-made tools to prepare and format text. One tool, for Word, marks the text with some tags (especialy for paragraph an charater styles). That maked text looks something like this:

       

      grep1.PNG

       

      after importing the text i run my script that (among other things) does some changeGrep like:

      find: <cStyle:Red>(.+?)</cStyle>

      replace: $1 //applied character style: Red

      after that, everything seems fine:

       

      grep2.PNG

       

      the next step is to change the paragraph styles:

      find: <pStyle:para1>(.+?)</pStyle>

      replace: $1 //applied paragraph style: para1

      after this step, the red text is shifted by 14 characters (the length of the pStyle tag).

       

      grepfail.PNG

       

      the simple fix would be to first change the outer-most tags (pStyle), and only after that the inner ones (cStyle, in this case), but in my case that is.. amost imposible to do, as my script handles not only basic formating but also tables, positioning, colors, inline elements, text variables etc.

      can anyone, please give me a idea how to fix it?

        • 1. Re: (JS) Grep problems
          [Jongware] Most Valuable Participant

          You can try doing each replace in two steps, rather than 1. First apply the paragraph style; don't replace the text (not even 'with itself'). Then loop over it again and remove the <pstyle> tags.

          1 person found this helpful
          • 2. Re: (JS) Grep problems
            Vamitul Level 4

            that's how i do it now, as the script runs, it builds a list of tags that can be removed at the end.

            the problem is when there is a error. for example if inside a paragraph there is a footnote, findGrep will ignore the said paragraph, and at the end when the script removes the tags, that paragraph will remain unprocessed, and also unmarked.

             

            (ps. the footnote is just a example, that i actually fixed, but there can be any other kind of error that leaves a tag unprocessed)

            • 3. Re: (JS) Grep problems
              [Jongware] Most Valuable Participant

              What if you only remove 'correct' <pstyle> markings in the second run? I.e., only search for <pstyle:x> in the style 'x'? Then you'd only have <pstyle>s left that failed in the first loop.

              • 4. Re: (JS) Grep problems
                Vamitul Level 4

                yep, but the closing tags are killing me.. how do i know to remove the proper </pStyle>