Skip to content
Advertisement

Python – Finding substrings related to specific keywords

I would like to ask you how I can extract substrings related to some keywords.

For example I have the following text:

JavaScript

I would like to extract the numeric value after some keywords, for example: “Discount” and “Other discount”. I was trying with the following code:

JavaScript

I would like to obtain (in this case) a pair –> Discount : 0,0120 and Other discount : 0,0000 But it could be also enough obtain a list like the following one:

JavaScript

I really thanks in advance for any help.

Advertisement

Answer

I had better luck with re.search. Also you were missing d,d to capture numbers before and after the comma.

JavaScript
Advertisement