fork(4) download
  1. import re
  2.  
  3. rx = r'\d(?=(?:\d{3})+(?!\d))'
  4. print re.sub(rx, '\g<0>,', 'The number is: 123')
  5. print re.sub(rx, '\g<0>,', 'The number is: 1234')
  6. print re.sub(rx, '\g<0>,', 'The number is: 12345')
  7. print re.sub(rx, '\g<0>,', 'The number is: 123456')
  8. print re.sub(rx, '\g<0>,', 'The number is: 1234567')
Success #stdin #stdout 0.01s 9016KB
stdin
Standard input is empty
stdout
The number is: 123
The number is: 1,234
The number is: 12,345
The number is: 123,456
The number is: 1,234,567