Community
    • Login

    How to put symbols after every letter

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    symbol
    6 Posts 3 Posters 1.2k 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.
    • Rahim GreedR
      Rahim Greed
      last edited by

      Hello,guys! Pls help to solve my issue in notepad++) I have a text:

      1&K@M@Z# no parts
      2&iv3c0# wheels,glass
      3&KIA# no parts

      I need:
      1.(with out last DOT)

      1&K.@.M.@.Z# no parts
      2&i.v.3.c.0# wheels,glass
      3&K.I.A# no parts

      2.(with last DOT)

      1&K.@.M.@.Z.# no parts
      2&i.v.3.c.0.# wheels,glass
      3&K.I.A.# no parts

      I want to add symbol “.” after every letter between symbols “&” and “#” with out touching other text.Please help with 2 possible solutions.
      Thanks a lot for help!

      Neil SchipperN PeterJonesP 2 Replies Last reply Reply Quote 0
      • Neil SchipperN
        Neil Schipper @Rahim Greed
        last edited by

        @rahim-greed Hello. I’m probably going to leave this for one of the eggheads who know techniques that can achieve this in one pass.

        However, if I were to try solving this (in multiple passes) I’d want to know the following about the original text:

        1. min and max number of chars between “&” and “#”

        2. if it’s guaranteed that there is never “.” between “&” and “#” (which would result in output with triples or greater of consecutive “.”)?

        1 Reply Last reply Reply Quote 0
        • PeterJonesP
          PeterJones @Rahim Greed
          last edited by PeterJones

          @rahim-greed ,

          Your question boils down to “how to do a regex search and replace, but only between some START and END condition”. So, this post by @guy038 shows how to do just that, with a generic regex.

          4c5763a7-7841-405e-967f-45e6b89fc275-image.png

          We just then have to figure out the terms to put in. And except for the fact that you wanted every character between those markers to get replaced with itself and a dot, it would have been a fairly simple application of that; I had to do a little bit of debug to get it to work with the every-character-between – but most regex do take some debug.

          In your case, the BEGIN (BSR) would have to be \& (to signify the literal & character, because & has special meaning to regex), and END (ESR) would be #. The FIND (FR) would be . (for match any character) and the REPLACE (RR) would be ${0}. (to add the dot after the found character).

          But actually, because the FR is ., that countermands the (?!#), so we also need a (?!#) in the FR to prevent it from going beyond.

          So

          • FIND = (?-i:\&|(?!\A)\G)(?s:(?!#).)*?\K(?-i:(?!#).)
          • REPLACE = ${0}.
            will result in
          1&K.@.M.@.Z.# no parts
          2&i.v.3.c.0.# wheels,glass
          3&K.I.A.# no parts
          

          That was the “with last DOT” condition.

          Now for the “without last DOT” condition: To tweak it to not allow the last character before the # to match and get a dot appended, add another negative lookahead after the dot in the FR:

          • FIND = (?-i:\&|(?!\A)\G)(?s:(?!#).)*?\K(?-i:(?!#).(?!#))
          • REPLACE = ${0}.
            will result in
          1&K.@.M.@.Z# no parts
          2&i.v.3.c.0# wheels,glass
          3&K.I.A# no parts
          

          I believe those match your desires.

          PeterJonesP 1 Reply Last reply Reply Quote 1
          • PeterJonesP
            PeterJones @PeterJones
            last edited by PeterJones

            It was pointed out to me that & does not have special meaning in the FIND (it just seems to me like it should, because $& in the replace section does have special meaning). So you can “simplify” by one character in each of the FIND expressions:

            • (?-i:&|(?!\A)\G)(?s:(?!#).)*?\K(?-i:(?!#).)
              or
            • (?-i:&|(?!\A)\G)(?s:(?!#).)*?\K(?-i:(?!#).(?!#))

            And yes, I did confirm that all 4 of those FIND values (my original two, and the “simplified” two) give the expected values as shown in my previous post.

            Neil SchipperN 1 Reply Last reply Reply Quote 1
            • Rahim GreedR
              Rahim Greed
              last edited by

              Thank you guys!

              1 Reply Last reply Reply Quote 0
              • Neil SchipperN
                Neil Schipper @PeterJones
                last edited by

                @peterjones

                My humble solutions require you to bang on “replace all” until the status becomes “0 occurrences were replaced…”

                Find1: (?<=&)(.*)([^\.])(?!\.)(.*)(?=.#)  ==> adds .'s from right, does not add rightmost; tests OK
                Find2: (?<=&)(.*)([^\.])(?!\.)(.*)(?=#)  ==> adds .'s from right, does add rightmost; tests OK
                ReplWith: $1$2.$3
                

                However, there is also an advantage. With the high powered ones, if you issue a subsequent “replace all”, the data gets mucked up. My regexes do nothing after the job is all done.

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