Community
    • Login

    How do i replace only digits attached with letters

    Scheduled Pinned Locked Moved General Discussion
    10 Posts 5 Posters 2.7k 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.
    • Ebenezer Amoako YirenkyiE
      Ebenezer Amoako Yirenkyi
      last edited by Ebenezer Amoako Yirenkyi

      i have
      PTH 284 Wo, mm4b chunu Awurade
      and i want to change only the 4 within the string without affect the 284
      so i want to change 4 to e
      so the result i need is
      PTH 284 Wo, mmeb chunu Awurade

      EkopalypseE 1 Reply Last reply Reply Quote 0
      • EkopalypseE
        Ekopalypse @Ebenezer Amoako Yirenkyi
        last edited by Ekopalypse

        @Ebenezer-Amoako-Yirenkyi

        given your requirement one possible solution would be to
        search for \d(?=[a-zA-Z]) , replace with e and
        having search mode regular expression checked.

        If the requirement is that the digit is surrounded by letters, then
        search for (?<=[a-zA-Z])\d(?=[a-zA-Z])

        Ebenezer Amoako YirenkyiE 1 Reply Last reply Reply Quote 1
        • guy038G
          guy038
          last edited by guy038

          ello @ebenezer-amoako-yirenkyi and All,

          To change any number, embedded in letters of a word, use the following regex S/R :

          • Open the Replace dialog ( Ctrl + F )

          -SEARCH (\p{alpha})\d+(?=\p{alpha})

          • REPLACE ${1}Your replacement ( So ${1}e, in your case )

          • Tick the Wrap around option, if necessary

          • Select the Regular expression search mode

          • Click once the Replace All button or several times on the Replace button

          Best Regards

          guy038

          Alan KilbornA Ebenezer Amoako YirenkyiE 2 Replies Last reply Reply Quote 2
          • Alan KilbornA
            Alan Kilborn @guy038
            last edited by

            @guy038 said in How do i replace only digits attached with letters:

            Open the Replace dialog ( Ctrl + F )

            Of course you meant Ctrl + h for this.

            Nice use of \p{alpha} from the Character Properties table on this PAGE which has a link that lead to HERE and then finally HERE to find “alpha”.

            Perhaps \p{space} will start getting more use as a more “readable” way of searching for whitespace? Although I’d have to go off and figure out exactly what types of whitespace it matches. :-)

            I also noted your use of ${1} in the replacement, rather than the usual \1. I think that is a good thing, because it looks “cleaner”, it features no “leaning toothpick”, and it works when the number part is > 9.

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

              @Alan-Kilborn said in How do i replace only digits attached with letters:

              Nice use of \p{alpha} from the Character Properties table on this PAGE which has a link that lead to HERE and then finally HERE to find “alpha”.

              Or you could go to our documentation on character properties which direct you to the big old table of valid names right above. :-)

              Alan KilbornA 1 Reply Last reply Reply Quote 3
              • Alan KilbornA
                Alan Kilborn @PeterJones
                last edited by

                @PeterJones said in How do i replace only digits attached with letters:

                Or you could go to our documentation on character properties

                Yea, since “our” docs on this are pretty much a verbatim copy of the original, I like to go back to the original, because of the “typo” potential in the copy/edit. :-)

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

                  @Alan-Kilborn said in How do i replace only digits attached with letters:

                  Although I’d have to go off and figure out exactly what types of whitespace it matches. :-)

                  Actually, @guy038 did that work back in November: [\t\n\x0B\f\r\x20\x85\xA0\x{2028}\x{2029}]
                  (merged in PR#59) …

                  edit: and you would have seen that if you used “ours” instead of “theirs” ;-)

                  1 Reply Last reply Reply Quote 2
                  • guy038G
                    guy038
                    last edited by guy038

                    Hi @ebenezer-amoako-yirenkyi @alan-kilborn, @peterjones and All,

                    Alan, I used the ${1} syntax because I was afraid that, in case you would have preferred to change the 4 digit, by any number, this would not work.

                    Luckily, I realize that I was wrong because, for instance, the syntax \123, in replacement, always means change current match with contents of group 1, ( even if not defined => an empty string), followed with the number 23

                    So, the two replacement syntaxes \1Your replacement or ${1}Your replacement are safe ! Unlike the third syntax $1Your replacement which is best to avoid when your replacement is a number !

                    BR

                    guy038

                    1 Reply Last reply Reply Quote 2
                    • Ebenezer Amoako YirenkyiE
                      Ebenezer Amoako Yirenkyi @guy038
                      last edited by

                      @guy038 it worked perfectly

                      1 Reply Last reply Reply Quote 1
                      • Ebenezer Amoako YirenkyiE
                        Ebenezer Amoako Yirenkyi @Ekopalypse
                        last edited by

                        @Ekopalypse it worked perfectly thanks for the help

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