Search code examples
notepad++

Reorganize number order


I have a form like this:

seven digits - three numbers - two - two numbers

live example:

7777777 - 123 - 12 - 12

I want to reorganize the form and put every three I have in the list in the last of the line

to become like this

7777777 - 12 - 12 - 123

“-” is just for separation purpose my form has no “-” included just spaces

is this possible by using notepad++? Thanks!


Solution

  • Assuming that all your lines are the same format, you can do replace with regex:

    Find what:

    (\d+)(\s+)(\d+)(\s+)(\d+)(\s+)(\d+)
    

    Replace with:

    $1$4$5$6$7$2$3
    

    Make sure to have "Regular expression" checked

    This will in every line which consists of 4 blocks of numbers (the count of numbers in each block does not matter) move the second block of numbers to be the last one. \d+ searches of a block of numbers (at least 1), \s+ searches for a block of whitespaces (at least 1). (\d+) is a capturing group, such that you can access the found block in the replacement by its number $1 ... $7. So $1 is the first block of digits, $2 is the first block of whitespaces, $3 is the second block of digits, $4 is the second block of whitespaces, and so on. By reordering the blocks, it moves the second block of digits to be the last one.