I am trying to find a regular expression to comma separate a large number based on the south asian numbering system.
A few examples:
1,000,000
(Arabic) is 10,00,000
(Indian/Hindu/South Asian)
1,000,000,000
(Arabic) is 100,00,00,000
(Indian/H/SA).
The comma pattern repeats for every 7 digits. For example,
1,00,00,000,00,00,000
.
From the book Mastering Regular Expressions by Friedl , I have the following regular expression for Arabic numbering system:
r'(?<=d)(?=(d{3})+(?!d))'
For Indian numbering system, I have come up with the following expression but it doesn't work for numbers with more than 8 digits:
r'(?<=d)(?=(((d{2}){0,2}d{3})(?=)))'
Using the above pattern, I get 100000000,00,00,000
.
I am using the Python re
module (re.sub()
). Any ideas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…