Loading ...
Sorry, an error occurred while loading the content.
 

Re: Can I replace text, depending on other text in the same line?

Expand Messages
  • John H. Lindsay
    Great question; I can t say whether NoteTab search and replace can do that sort of job, but that sort of thing, especially for a big file, is a job for
    Message 1 of 9 , May 4, 2012
      Great question; I can't say whether NoteTab search and
      replace can do that sort of job, but that sort of thing, especially
      for a big file, is a job for SNOBOL4. While some amazing
      programmes have been done in SNOBOL4, including big
      ones, SNOBOL4 is a total winner on short 10-20-30 line one-off
      jobs. SNOBOL4 is not only a string recognition, decomposition
      and processing language but also a data structures building
      and handling language. One job that I did with it, many years
      ago, was a programme that took as input a large IBM 360
      assembly language source programme written with all the
      register references coded as numbers, and gave as output an
      equivalent programme with all the numeric register references
      transformed into defined symbols, so that the register references
      showed in the symbol cross-reference at the end of the assembly
      listing, and bugs involving the misuse of registers could be found.

      For details, documentation and compilers, including free ones,
      see

      http://www.snobol4.com

      John.
    • Art Kocsis
      ... Thanks for the trip down memory lane. I haven t seen SNOBOL since grad school mbl mmbl years ago. SOBOL and LISP were quite a different experience for a
      Message 2 of 9 , May 4, 2012
        At 5/4/2012 08:00 AM, John wrote:
        >Great question; I can't say whether NoteTab search and
        >replace can do that sort of job, but that sort of thing, especially
        >for a big file, is a job for SNOBOL4. While some amazing
        >programmes have been done in SNOBOL4, including big
        >ones, SNOBOL4 is a total winner on short 10-20-30 line one-off
        >jobs.

        Thanks for the trip down memory lane. I haven't seen SNOBOL
        since grad school mbl mmbl years ago. SOBOL and LISP were
        quite a different experience for a FORTRAN programmer.

        Art
      • flo.gehrke
        ... Search: (ABC(?=.+KLM))|(KLM.* KABC) Replace with: DEFGH Regular Exp.: checked Tested against... ABC to DEFGH if line KLM. KLM to DEFGH if line ABC. ABC to
        Message 3 of 9 , May 5, 2012
          --- In notetab@yahoogroups.com, "Brian" <lowbrian@...> wrote:
          >
          > Hello all. I want to do a Find and Replace, changing a string of
          > characters to a longer string of different characters - but only
          > on lines that contain another string. For example - change all
          > occurrences of ABC to DEFGH if the same line also contains KLM.
          > Is there a way of doing this? I am using NoteTab Pro 6.2/fv.

          Search: (ABC(?=.+KLM))|(KLM.*\KABC)
          Replace with: DEFGH
          Regular Exp.: checked

          Tested against...

          ABC to DEFGH if line KLM.
          KLM to DEFGH if line ABC.
          ABC to DEFGH if ABC line KLM.
          ABC to DEFGH if line.
          ABC ABC to DEFGH if line KLM.
          DEFGH if ABC line KLM ABC.
          KLM ABC to DEFGH if line KLM.
          DEFGH if ABC line.

          This is not the Clip Group -- but, certainly, you are better off with a simple clip like this (discounting further details like 'case', 'whole word' etc)...

          ^!Jump Doc_Start
          ^!Find "^.*?KLM.*$" RS
          ^!IfError End
          ^!Replace "ABC" >> "DEFGH" HAS
          ^!Goto Skip_-3

          Regards,
          Flo

          NT Pro 6.2 / NT Pro 7.0, Pre-release #8
        • mycroftj
          First, Thanks to Flo for the great answers and examples. I learn more by studying them than anything else. Question: Shouldn t (?=.+KLM) be (?=.*KLM) so KLM
          Message 4 of 9 , May 6, 2012
            First, Thanks to Flo for the great answers and examples. I learn more by studying them than anything else.

            Question: Shouldn't (?=.+KLM) be (?=.*KLM) so KLM directly after ABC is found?

            Next, I tried the clip even though it looked simple and I thought I understood it but something strange happened and it seems like a bug to me. Please check.

            I added the following two lines to the end of the original data
            ABCKLM
            KLMABC

            When I ran the clip, it replaced all the ABCs it should have EXCEPT FOR on the two new lines. The lines were selected by the FIND, but the REPLACE did nothing. The manual REPLACE example provided by FLO with the * instead of + worked fine.

            This is in NTL V7 pr 8.

            Joy



            --- In notetab@yahoogroups.com, "flo.gehrke" <flo.gehrke@...> wrote:
            >
            > --- In notetab@yahoogroups.com, "Brian" <lowbrian@> wrote:
            > >
            > > Hello all. I want to do a Find and Replace, changing a string of
            > > characters to a longer string of different characters - but only
            > > on lines that contain another string. For example - change all
            > > occurrences of ABC to DEFGH if the same line also contains KLM.
            > > Is there a way of doing this? I am using NoteTab Pro 6.2/fv.
            >
            > Search: (ABC(?=.+KLM))|(KLM.*\KABC)
            > Replace with: DEFGH
            > Regular Exp.: checked
            >
            > Tested against...
            >
            > ABC to DEFGH if line KLM.
            > KLM to DEFGH if line ABC.
            > ABC to DEFGH if ABC line KLM.
            > ABC to DEFGH if line.
            > ABC ABC to DEFGH if line KLM.
            > DEFGH if ABC line KLM ABC.
            > KLM ABC to DEFGH if line KLM.
            > DEFGH if ABC line.
            >
            > This is not the Clip Group -- but, certainly, you are better off with a simple clip like this (discounting further details like 'case', 'whole word' etc)...
            >
            > ^!Jump Doc_Start
            > ^!Find "^.*?KLM.*$" RS
            > ^!IfError End
            > ^!Replace "ABC" >> "DEFGH" HAS
            > ^!Goto Skip_-3
            >
            > Regards,
            > Flo
            >
            > NT Pro 6.2 / NT Pro 7.0, Pre-release #8
            >
          • flo.gehrke
            ... Joy, ... I didn t take into account that we could meet with a string ABCKLM . Unfortunately, we were never informed of the list the member is trying to
            Message 5 of 9 , May 6, 2012
              --- In notetab@yahoogroups.com, "mycroftj" <mycroftj@...> wrote:
              >
              > First, Thanks to Flo for the great answers and examples.
              > I learn more by studying them than anything else...

              Joy,

              > Question: Shouldn't (?=.+KLM) be (?=.*KLM) so KLM directly
              > after ABC is found?

              I didn't take into account that we could meet with a string 'ABCKLM'. Unfortunately, we were never informed of the list the member is trying to process. So we have to adjust the clip to specific needs, of course.

              > Next, I tried the clip even though it looked simple and I thought I
              > understood it but something strange happened and it seems like a bug
              > to me. Please check.

              No bug. 'DEFKLM' or 'KLMDEF' is matched only if, in this specific case, the 'T' option is set:

              ^!Replace "ABC" >> "DEF" HAST

              Cf. the Help on Clip Programming: "If the options T or C are not used, NoteTab will search for whole words if the search criteria does not contain spaces or other word delimiting characters. If the search criteria contains such delimiters, then NoteTab will accept matches that are not whole words."

              With RegEx, as in my proposal meant for the menu command, it's different because, normally, RegEx don't distinguish between substring and whole word unless you use word delimiters.

              Regards,
              Flo
            • mycroftj
              ... Aaaaaaaaand I keep learning. Thank you for the explanation. I ve always had a bit of trouble with the way that was worded but think I get it now. Joy
              Message 6 of 9 , May 6, 2012
                --- In notetab@yahoogroups.com, "flo.gehrke" <flo.gehrke@...> wrote:
                >
                > --- In notetab@yahoogroups.com, "mycroftj" <mycroftj@> wrote:
                > >
                > > First, Thanks to Flo for the great answers and examples.
                > > I learn more by studying them than anything else...
                >
                > Joy,
                >
                > > Question: Shouldn't (?=.+KLM) be (?=.*KLM) so KLM directly
                > > after ABC is found?
                >
                > I didn't take into account that we could meet with a string 'ABCKLM'. Unfortunately, we were never informed of the list the member is trying to process. So we have to adjust the clip to specific needs, of course.
                >
                > > Next, I tried the clip even though it looked simple and I thought I
                > > understood it but something strange happened and it seems like a bug
                > > to me. Please check.
                >
                > No bug. 'DEFKLM' or 'KLMDEF' is matched only if, in this specific case, the 'T' option is set:
                >
                > ^!Replace "ABC" >> "DEF" HAST
                >
                > Cf. the Help on Clip Programming: "If the options T or C are not used, NoteTab will search for whole words if the search criteria does not contain spaces or other word delimiting characters. If the search criteria contains such delimiters, then NoteTab will accept matches that are not whole words."
                >
                > With RegEx, as in my proposal meant for the menu command, it's different because, normally, RegEx don't distinguish between substring and whole word unless you use word delimiters.
                >
                > Regards,
                > Flo
                >

                Aaaaaaaaand I keep learning.
                Thank you for the explanation. I've always had a bit of trouble with the way that was worded but think I get it now.

                Joy
              • Brian
                Thanks for the responses to my question on this. My first post - what a helpful lot you are! Flo s search string ((ABC(?=.+KLM))|(KLM.* KABC)) was great. It
                Message 7 of 9 , May 7, 2012
                  Thanks for the responses to my question on this. My first post - what a helpful lot you are!

                  Flo's search string ((ABC(?=.+KLM))|(KLM.*\KABC)) was great. It was easy to tailor it to the actual strings I was working with, it did just what I wanted and solved my problem. You would probably expect that, seeing how it had been tested by Flo, as documented in the message. I'll admit to knowing little about regular expressions, so I've got some work to do to understand why it works.

                  SNOBOL4 ... I've no experience with that, though I once enquired about a job using it. I think it was investigating natural language translation. But for this problem I was looking at coding something in a .NET language with its string handling. Fortunately, I've been saved from that.

                  Regards,
                  Brian


                  --- In notetab@yahoogroups.com, "flo.gehrke" <flo.gehrke@...> wrote:
                  >
                  >
                  > Search: (ABC(?=.+KLM))|(KLM.*\KABC)
                  > Replace with: DEFGH
                  > Regular Exp.: checked
                  >
                  > Tested against...
                  >
                  > ABC to DEFGH if line KLM.
                  > KLM to DEFGH if line ABC.
                  > ABC to DEFGH if ABC line KLM.
                  > ABC to DEFGH if line.
                  > ABC ABC to DEFGH if line KLM.
                  > DEFGH if ABC line KLM ABC.
                  > KLM ABC to DEFGH if line KLM.
                  > DEFGH if ABC line.
                  >
                  > This is not the Clip Group -- but, certainly, you are better off with a simple clip like this (discounting further details like 'case', 'whole word' etc)...
                  >
                  > ^!Jump Doc_Start
                  > ^!Find "^.*?KLM.*$" RS
                  > ^!IfError End
                  > ^!Replace "ABC" >> "DEFGH" HAS
                  > ^!Goto Skip_-3
                  >
                  > Regards,
                  > Flo
                  >
                  > NT Pro 6.2 / NT Pro 7.0, Pre-release #8
                  >
                Your message has been successfully submitted and would be delivered to recipients shortly.