• Login
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.
  • S
    serg oth
    last edited by Aug 26, 2021, 8:58 AM

    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

    A 1 Reply Last reply Aug 26, 2021, 11:47 AM Reply Quote 0
    • A
      Alan Kilborn @serg oth
      last edited by Aug 26, 2021, 11:47 AM

      @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

      S 1 Reply Last reply Aug 26, 2021, 1:11 PM Reply Quote 4
      • S
        serg oth @Alan Kilborn
        last edited by Aug 26, 2021, 1:11 PM

        @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)!!!

        A 1 Reply Last reply Aug 26, 2021, 1:14 PM Reply Quote 1
        • A
          Alan Kilborn @serg oth
          last edited by Aug 26, 2021, 1:14 PM

          @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?

          S 1 Reply Last reply Aug 26, 2021, 1:16 PM Reply Quote 0
          • S
            serg oth @Alan Kilborn
            last edited by Aug 26, 2021, 1:16 PM

            @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
            • A
              Alan Kilborn
              last edited by Aug 26, 2021, 1:20 PM

              @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?

              A S 2 Replies Last reply Aug 26, 2021, 1:30 PM Reply Quote 2
              • A
                Alan Kilborn @Alan Kilborn
                last edited by Alan Kilborn Aug 26, 2021, 1:30 PM Aug 26, 2021, 1:30 PM

                @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
                • S
                  serg oth @Alan Kilborn
                  last edited by Aug 26, 2021, 1:30 PM

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

                  A 1 Reply Last reply Aug 26, 2021, 1:37 PM Reply Quote 0
                  • A
                    Alan Kilborn @serg oth
                    last edited by Alan Kilborn Aug 26, 2021, 1:37 PM Aug 26, 2021, 1:37 PM

                    @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?”.

                    S 1 Reply Last reply Aug 26, 2021, 1:47 PM Reply Quote 3
                    • S
                      serg oth @Alan Kilborn
                      last edited by Aug 26, 2021, 1:47 PM

                      @Alan-Kilborn Thanks a lot. Everything is clear

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