4 Replies Latest reply on May 30, 2012 5:25 PM by peter minneapolis

    Could GREP be used to assist in the following

    Jeffrey_Smith Most Valuable Participant

      I have a list as follows:

      123A

      123B

      123C

      123D

      124A

      124B

      124D

      125B

      125C

       

      I need to format the list into a table as follows:

      Header AHeader BHeader CHeader D
      123A123B123C123D
      124A124B
      124D

      125B125C

       

      Question 1: With my example list, replace all returns with tabs, then replace every fourth tab with a return, Is the second part possbile with GREP?

       

      Question 2: Is it possible to search for the letter and then replace with something that could effectively add a blank so list would fall into appropriate column? (in my example there is no 124C, but 124D needs to be in the D column)

        • 1. Re: Could GREP be used to assist in the following
          [Jongware] Most Valuable Participant

          1. That would be Search

           

          ((\t.+?){3})\t

           

           

           

          Replace

           

          $1\r

           

          2. Nah. .. Oh, wait. After replacing hard returns with tabs, you could try this:

           

          (B)\t([^\t]+(?<!C))\t

           

          -- this seems to find the missing one, but creating a proper find/replace string is a bit of a hassle. Also, you need to run this for A-B, B-C, C-D, and perhaps even D-A.

          • 2. Re: Could GREP be used to assist in the following
            Jeffrey_Smith Most Valuable Participant

            Thanks Jongware, the answer for question 1 will get me on my way. The actual list does not have any set pattern for the number of blanks to be inserted. One incidence may need one tab for a blank, the next may need three tabs, etc. So this may be impossible to automate.

            • 3. Re: Could GREP be used to assist in the following
              [Jongware] Most Valuable Participant

              Oh yeah, the number of tqbs to insert would be a problem.

              But you still can use my 2nd GREP to look for missing parts, and add tabs by hand.

               

              If you do, I think you have to change the Insert Return GREP to match two or more tabs without anything in between. Untested, but you could then try this:

               

              ((\t.*?){3})\t

               

              this should match NONE or more characters between tabs.

              • 4. Re: Could GREP be used to assist in the following
                peter minneapolis Level 4

                I'm barely GREP-literate, but I wonder if the source content is sufficiently regular so that it's possible to test the number of instances for each new number, then replace any missing instance of the number that isn't A, B, C, or D, with a placeholder, so that each number has four instances. For example, store the first number, say 123 with any trailing letter, count how many 123 instances exist, if the first 123 is not 123A, create it, if it is 123A, move to the next instance. If the next instance is 123B, move on; if not, create 123B and move on. Process 123C and 123D the same. Move on to the next, which should be an instance of 124. Repeat until done. Once all the needed placeholders have been created, apply a non-printing attribute or color.

                 

                If multiple passes are required for GREP, perhaps scripting would work.

                 

                HTH

                 

                 

                Regards,

                 

                 

                Peter

                _______________________

                Peter Gold

                KnowHow ProServices

                 

                [Jongware] wrote:

                 

                Oh yeah, the number of tqbs to insert would be a problem.

                But you still can use my 2nd GREP to look for missing parts, and add tabs by hand.

                 

                If you do, I think you have to change the Insert Return GREP to match two or more tabs without anything in between. Untested, but you could then try this:

                 

                ((\t.*?){3})\t

                 

                this should match NONE or more characters between tabs.