There is a text file:
не нужная текстовая строчка Иванов 15.1 10е9/л (4.0 - 1 о.о) >1 Петров 11.5 10е9/л (о - 5) Сидоров 0.8 10е9/л (о - 2) Мельников 2 10е9/л (1 - 8) I need to extract the Surnames and their numeric values after the space. So that the output is such a result:
Иванов: 15.1 Петров: 11.5 Сидоров: 0.8 Мельников: 2 I already have a pattern with a regular expression, but it extracts the values, not as I need.
matches_list = re.findall(r'([\w\s]+).+?(\d*\.\d+|\d+)', content, flags=re.DOTALL | re.U) Please help me to make a regular expression.
list(map(lambda x: ': '.join(x), re.findall(r'(\S+)(?:\s+)?\n(\d+(?:\.\d+)?)', content))), wherecontentis the content of the file. But it is rather a head-on solution. It is probably better to usere.subto scatter the captured groups on the specified pattern " name: number ". - greg zakharov(\w+)\s*\n([\d\.]+)- Let's say Pie