Help with finding numeric string



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



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


  • @Liz-Pitre

    A possible solution:

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

    Cryptic? Complicated? Necessary? Yep Maybe Definitely



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



  • 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!



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


Log in to reply