• Login
Community
  • Login

Help with finding numeric string

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
find and add
6 Posts 4 Posters 18.5k 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.
  • L
    Liz Pitre
    last edited by Jan 17, 2019, 6:32 PM

    Help! I need to find a numeric string and add some characters after it. For example: Find ‘12345678 and replace with ‘12345678’), (’

    E A 2 Replies Last reply Jan 17, 2019, 6:35 PM Reply Quote 0
    • E
      Eko palypse @Liz Pitre
      last edited by Jan 17, 2019, 6:35 PM

      @Liz-Pitre

      are you looking for a more general approach like numbers might vary then
      you could use regular expression replace but if the number is fixed and known
      you can find and replace with the number.
      So a regex looks like

      find: (\d+)
      replace \1sometext
      

      and normal search replace would be

      find: 123456
      replace 123456sometext
      
      1 Reply Last reply Reply Quote 4
      • A
        Alan Kilborn @Liz Pitre
        last edited by Jan 17, 2019, 6:43 PM

        @Liz-Pitre

        A possible solution:

        Find what '\d+
        Replace with $0'\),\('
        Search mode: Reg expression

        Cryptic? Complicated? Necessary? Yep Maybe Definitely

        1 Reply Last reply Reply Quote 3
        • T
          Terry R
          last edited by Terry R Jan 17, 2019, 6:57 PM Jan 17, 2019, 6:56 PM

          @Liz-Pitre said:

          For example: Find ‘12345678 and replace with…

          What you will hopefully gather from the 2 responses so far is that you have provided very little to work with. The “for example” suggests you may want to find other instances of numbers different from each other. This is where the power of “regular expressions” (regex) comes into play. It acts like a filter, \d+ means find a number, the plus means it can be as many digits as possible, so long as no other character (or space) interrupts it.

          If you want to specifically search for 12345678 and no other number then the search mode (if using Notepad++ replace function) is ‘normal’.

          As the additional characters are ‘special ones’ (the 2 round brackets) with regards a regex, it becomes a bit more involved to add these if using a regex, over a normal search.

          Essentially, what we really need from you is additional information on the types of numbers you are searching for (maybe a fixed length of digits), they may be formatted in a particular way (12-345-678) or possibly you ONLY want numbers starting with 1 to be changed (1x-xxx-xxx, x being any digit).

          We await your reply.

          Terry

          1 Reply Last reply Reply Quote 3
          • L
            Liz Pitre
            last edited by Jan 17, 2019, 7:58 PM

            The numbers vary. I just used 12345678 as an example. There are over 2,000 lines with different CUSTOMER ID’s that may have 7 or 8 characters. Using Alan’s suggestion helped tremendously. Terry, thank you for the explanation. I’m very new to REGEX but looking forward to learning more in this community. Thanks for your help!

            1 Reply Last reply Reply Quote 5
            • T
              Terry R
              last edited by Jan 17, 2019, 8:39 PM

              @Liz-Pitre
              Thanks for getting back to us. Yes, regex will definitely help you when you have a range of numbers to search for and update/replace.

              Just be careful though, that if your data contains ANY other numbers the regex \d+ will find them ALL.

              Sometimes telling us more about what you don’t want changed can help as much as what you do want changed. In this case you told us the digits which need replacing are either 7 or 8 digits long. We could make a regex which works ONLY on this data if needed.

              In terms of learning more about NPP (wording used synonymously with Notepad++) and about the regex engine within NPP may I direct you to our FAQ section. Within are lots of links to various websites which will help in your learning process. Also feel free to ask on this forum when it’s NPP related.

              Welcome.

              Terry

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