Home > OS >  How to filter Euro numbers with regular expression?
How to filter Euro numbers with regular expression?

Time:09-26

I try to filter the decimal numbers after the € symbol. So I have this string:

Crownless 14kg 10 Sweet CR Klasse I € 7,00 € 3.962,00\n706 Appels Royal Gala 13kg 60/65 Generica PL Klasse I € 4,68 € 3.304,08\n598 Peen Waspeen 14x1lkg 200-400 Generica BE Klasse I € 6,30 3.767,40\nOrder number : 76462 Loading date : 18-11-21 Incoterm: : FOT\nYour ref. : SCHOOLFRUIT Delivery date"""

and so I want to have the decimal numbers:

7,00 3.962,00 4,68 3.304,08 ect

So I try it like this:

pattern = re.compile(r'€\s[1-9]\d*')

matches = pattern.finditer(test_string)    
 
for match in matches:
    print(match) 

So, if I try it like this. I only get the first number of the number after the euro symbol.

CodePudding user response:

You can use a capture group and re.findall, with a pattern matching the dots and comma's like:

€\s(\d (?:\.\d )*(?:,\d )?

Or a bit broader, starting with a digit 1-9 as the tried pattern:

€\s([1-9][\d.,]*)
  • Related