Python Forum
reformatting text with comma separated numbers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
reformatting text with comma separated numbers
#5
>>> import re
>>> pat_obj=re.compile('[0-9,]+')
>>> str='foo 4,566 bar 1,234'
>>>
>>> text=pat_obj.findall(str)
>>> for num in text:
...   str=str.replace(num,num.replace(',','').rjust(len(num),' '))
...
>>> str
'foo  4566 bar  1234'
Reply


Messages In This Thread
RE: reformatting text with comma separated numbers - by anbu23 - May-07-2020, 06:14 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  sorting with numbers in text Skaperen 5 3,793 Jul-20-2021, 01:15 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020