Regex for devision class number

Hello!
Can you please tell me what regular expression can be used to divide a multi-digit number/decimals into class numbers with non-breaking spaces

Only thing that worked looks very strange and it's not multipurposal.

E.g. for 9-digit number I used Find&Replace function

123456789

Find what: ([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])

Replace with: $1$2$3$ 4$5$6$ 7$8$9

This one could be used, but it absolutely useless with decimals 

Parents Reply
  • Because native regex has only limited formatting capabilities, it may be better to run a regex pair, where the first general regex performs the basic extraction and formatting, and the second regex performs the cleanup. 

    For example, 
    \b(\d{1,3})(\d{3})?(\d{3})?(\.(\d+))?\b
    with replacement expression
    $1 $2 $3,$5
    handles numbers with 1-9 digits before an optional period and 1 or more digits after an optional period. The regex could easily be extended to handle larger numbers.

    An alternative approach would be to code separate regexes to handle each number combination and execute them manually or automated (such as with AHK)


    Test strings:
    1 12 123 1234 12345 123456 1234567 1234567.93
    Associated result strings:
    1  , 12  , 123  , 1 234 , 12 345 , 123 456 , 1 234 567, 1 234 567,93

    A cleanup regex removes any superfluous punctuation.

Children