import re
#Example 1
input_str = "creo que hay 330 trillones 2 billones 18 millones 320 mil 459 47475822"
#Example 2
input_str = "sumaria 6 cuatrillones 789 billones 320 mil a esta otra cantidad de elementos 47475822 y eso daría por resultado varios millones o trillones de unidades"
mil = 1000
2 mil = 2000
322 mil = 322000
1 millon = 1000000
2 millones = 2000000
1 billon = 1000000000000
25 billones = 25000000000000
1 trillon = 1000000000000000000
3 trillones = 3000000000000000000
1 cuatrillon = 1000000000000000000000000
mil = 1 digit followed 3 digits
millon = 1 digit followed 6 digits
billon = 1 digit followed 6+6 digits
trillon = 1 digit followed 6+6+6 digits
cuatrillon = 1 digital followed 6+6+6+6 digits
The difference between them is 6, always 6 digits, which if they are not complete, they are indicated as 0, since the decimal system is positional (the positions of the important digits).
When it is said in the singular, for example, millon, it is because there is always a 1 in front, that is,"1 millon" and not "1 millones" (add es for not singular) but if it is greater than 1, it will be for example "2 trillones" = 2000000000000000000 or "320 billones" = 320000000000000.
"mil" is an exception since it does not have a plural, that is, 2 thousand "2 miles" is not used but "2 mil" is placed.
The other exception is that 1 thousand "1 mil" is not written but i write only "mil" and it is understood that it is "1000"
Proto regex for xxx mil xxx
r"\d{3}[\s|]*(?:mil)[\s|]*\d{3}"
Proto regex for millon, billon, trillon and cuatrillon
r"\d{6}[\s|]*(?:cuatrillones|cuatrillon)[\s|]*\d{6}[\s|]*
(?:trillones|trillon)[\s|]*\d{6}[\s|]*(?:billones|billon)[\s|:]*\d{6}[\s|:]*(?:millones|millon)[\s|:]*\d{6}"
Output that i need obtain with some replacement method like re.sub(), this method is to place some of the regex, since the replacement must be conditioned to be in the middle of this amount of numbers to be done, otherwise it should not be done (as seen in the output of example 2)
"3000000000000320459 47475822" #example 1
"sumaria 6000000000789000000320000 a esta otra cantidad de elementos 47475822 y eso daría por resultado varios millones o trillones de unidades" #example 2
How could I improve my regex to be able to perform these replacements correctly? Or maybe it is better to use another method?