Community
    • Login

    Help to replace signs

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    10 Posts 2 Posters 534 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • serg othS
      serg oth
      last edited by

      Hello. I got a huge text doc and I can not replace signs in document, I tried only replace, but it replaces all document. I have a text

      numric-:N1CK# deal OTHER!
      SIGN-:J0HN# deal ADAM!
      Zumric-:M1KE# deal TOGETHER!
      numric-:SV3NN# deal KORY!
      VOTE-:K!ND@# deal TOGETHER!
      Zumric-:N4C# deal TOGETHER!
      VOTE-:G@RR3TH# deal OTHER!

      and I need

      numric-:NICK# deal OTHER!
      SIGN-:JOHN# deal ADAM!
      Zumric-:MIKE# deal TOGETHER!
      numric-:SVENN# deal KORY!
      VOTE-:KINDA# deal TOGETHER!
      Zumric-:NAC# deal together!
      VOTE-:GARRETH# deal OTHER!

      I need only replace text between (:) and (#) chars , want to replace 1-I, 0-O, 3-E, @-A etc.
      Please help me to do that

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @serg oth
        last edited by

        @serg-oth said in Help to replace signs:

        want to replace 1-I, 0-O, 3-E, @-A etc.

        You can do that using this technique:

        Find: (0)|(1)|(2)|(3)|(4)
        Replace: (?1O)(?2I)(?3Z)(?4E)(?5A)
        Search mode: Regular expression
        Note: I guessed about the 2 -> Z transformation!

        For the “etc” part you just add more to the pattern.
        Example, replace 5 with S:
        Find: (0)|(1)|(2)|(3)|(4)|(5)
        Replace: (?1O)(?2I)(?3Z)(?4E)(?5A)(?6S)

        Note also that the number following the ?s in the Replace expression is one more than what you might think!

        I need only replace text between (:) and (#) chars

        For that part, we can apply the technique shown here:

        https://community.notepad-plus-plus.org/post/62799

        specifically:

        SEARCH (?-i:BSR|(?!\A)\G)(?s:(?!ESR).)*?\K(?-i:FR)
        REPLACE RR

        where BSR = :, ESR = #, FR and RR are as I showed above.

        Thus, completely, we have:

        Find: (?-i::|(?!\A)\G)(?s:(?!#).)*?\K(?-i:(0)|(1)|(2)|(3)|(4))
        Replace: (?1O)(?2I)(?3Z)(?4E)(?5A)
        Search mode: Regular expression
        Note: You must use Replace All to do the replacements

        serg othS 1 Reply Last reply Reply Quote 4
        • serg othS
          serg oth @Alan Kilborn
          last edited by

          @Alan-Kilborn could you,please write. how to convert it back as in begining?
          from
          numric-:NICK# deal OTHER!
          SIGN-:JOHN# deal ADAM!
          Zumric-:MIKE# deal TOGETHER!
          numric-:SVENN# deal KORY!
          VOTE-:KINDA# deal TOGETHER!
          Zumric-:NAC# deal together!
          VOTE-:GARRETH# deal OTHER!

          to
          numric-:N1CK# deal OTHER!
          SIGN-:J0HN# deal ADAM!
          Zumric-:M1KE# deal TOGETHER!
          numric-:SV3NN# deal KORY!
          VOTE-:K!ND@# deal TOGETHER!
          Zumric-:N4C# deal TOGETHER!
          VOTE-:G@RR3TH# deal OTHER!

          only replace text between (:) and (#) chars

          5 stars for you MAN! You are AWESOME)!!!

          Alan KilbornA 1 Reply Last reply Reply Quote 1
          • Alan KilbornA
            Alan Kilborn @serg oth
            last edited by

            @serg-oth said in Help to replace signs:

            could you,please write. how to convert it back as in begining?

            Hmm, I thought my explanation of the forward transform would have been enough to make something like that fairly obvious. Do you have any thoughts as to how you might do the reverse transform, other than asking me to do it?

            serg othS 1 Reply Last reply Reply Quote 0
            • serg othS
              serg oth @Alan Kilborn
              last edited by

              @Alan-Kilborn its only for me to know that kind of commands. Education only. Sorry for taking your time,man

              1 Reply Last reply Reply Quote 0
              • Alan KilbornA
                Alan Kilborn
                last edited by

                @Alan-Kilborn said in Help to replace signs:

                Find: (0)|(1)|(2)|(3)|(4)
                Replace: (?1O)(?2I)(?3Z)(?4E)(?5A)

                So if we look back at that…

                We are looking for 0 or 1 or 2 or 3 or 4 (from the “Find” expression)

                When we find one of those, at replace time we look at what we found, and replace it with something else.

                0 goes to O, 1 goes to I, etc.

                So, how hard is it to go the other way?

                You’d just swap the values in the find/replace specification.

                So the first one might be:
                F: (O)
                R: (?10)

                Get it?

                Alan KilbornA serg othS 2 Replies Last reply Reply Quote 2
                • Alan KilbornA
                  Alan Kilborn @Alan Kilborn
                  last edited by Alan Kilborn

                  @Alan-Kilborn said in Help to replace signs:

                  R: (?10)

                  Actually, it is not that simple. :-(

                  ?10 here is interpreted as a 10 not as a 1 followed by a 0.

                  @serg-oth

                  Ok, since that may not be easy to understand, I’ll give you the full solution to the reverse transform, rather than assisting you to think it through:

                  Find: (?-i::|(?!\A)\G)(?s:(?!#).)*?\K(?-i:(O)|(I)|(Z)|(E)|(A))
                  Replace: (?{1}0)(?{2}1)(?{3}2)(?{4}3)(?{5}4)
                  Search mode: Regular expression
                  Note: You must use Replace All to do the replacements

                  1 Reply Last reply Reply Quote 3
                  • serg othS
                    serg oth @Alan Kilborn
                    last edited by

                    @Alan-Kilborn I got it, bro. What about A-@, S-$, i-!
                    F(A)
                    R(?@)
                    right?

                    Alan KilbornA 1 Reply Last reply Reply Quote 0
                    • Alan KilbornA
                      Alan Kilborn @serg oth
                      last edited by Alan Kilborn

                      @serg-oth

                      I got it bro

                      You are at least thinking about how to apply it! Which is good!

                      F(A)

                      R(?@)

                      Close.

                      OK, so here’s the formula:

                      In the Find expression, you look from left to right at the parentheses groupings, ( and ). The first pair is group 1, the second pair is group 2, etc.

                      Then, in Replace, you use the group number after the ?.

                      So, in this simpler case:

                      Find: (O)|(I)
                      Replace: (?{1}0)(?{2}1)

                      you want to replace group number 1 (the O match) with 0, so you use ?{1} before the 0 in the replace.
                      Similarly, the I is in group number 2 in the find, so you refer to it as ?{2} in the replace.

                      You can think of the ? as “is this group number matched?”.

                      serg othS 1 Reply Last reply Reply Quote 3
                      • serg othS
                        serg oth @Alan Kilborn
                        last edited by

                        @Alan-Kilborn Thanks a lot. Everything is clear

                        1 Reply Last reply Reply Quote 2
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors