regex - Change number in last row in data seperated with commas in NotePad++

08
2014-07
  • user329311

    I have rows of data all separated with commas. How can I replace the last numbers after the last commas with the number 5 in NotePad++?

    For example: How do I replace 9, 17 and 124 with 5 in the below data? I have millions of rows though of data and Excel doesn't have enough rows for all the data.

    Sample data:

    2009.10.21,05:31,1.49312,1.49312,1.49306,1.49306,9
    2009.10.21,05:32,1.49306,1.49308,1.49303,1.49305,17
    2009.10.21,05:33,1.49305,1.4931,1.49305,1.49309,124
    

    Thank you for your help.

  • Answers
  • Excellll

    Use a regular expression to find the last number and replace it.

    Search pattern:

    [0-9\.]+$
    

    Replace with:

    5
    

    The search pattern matches any number (whole number or decimal) at the end of a line.

  • Seasoned Advice (cooking)

    These formulas worked for me when I tried them:

    Find what: [0-9]+\r\n
    Replace with: 5\r\n

    Edit: Be sure to check the last item in the file because it might not have changed if there is no return and newline after it.


  • Related Question

    notepad++ - regex pattern for various number groups
  • TheSavo

    I am parsing a list of code numbers, they have a pattern of 12345.1211. They are space delimited. They sometimes will have a space followed by one - three addition number patterns like: 1221.121 11 or 111.111111 874.95 1211

    I have a regex [0-9]+\.[0-9]+

    It finds a decimated number like 12345.1211 as . I encapsulate the regex with ( & ) and use \1\n to break each code with a newline.

    I am using Notepad++ with find an replace. But the regex falls short with the space-included numbers. The extra numbers endup on the same line as the next pattern.

    Example of 1221.121 11 or 111.111111 874.95 1211 456.155

    1221.121

    11 111.111111

    874.95

    1211 456.155

    Is there anything I can do to optionally include the extra numbers separated by a space?

    Thanks.


  • Related Answers
  • wonea

    On your test data this regex matches all the numbers perfectly for me;

    [0-9]+[.]?[0-9]+