Please tell me how to use the re from the next line to get the dictionary:
'ООО "П.Б. Ромашка" (ИНН: 00000000, ОГРН: 9999999)' I would like to receive
{'Наименование': 'ООО "П.Б. Ромашка"', 'ИНН': '00000000', 'ОГРН':'9999999'} Please tell me how to use the re from the next line to get the dictionary:
'ООО "П.Б. Ромашка" (ИНН: 00000000, ОГРН: 9999999)' I would like to receive
{'Наименование': 'ООО "П.Б. Ромашка"', 'ИНН': '00000000', 'ОГРН':'9999999'} If specifically from this, then, for example, like this:
s = 'ООО "П.Б. Ромашка" (ИНН: 00000000, ОГРН: 9999999)' r = re.match("(.*?)\s+\(.*:\s+(.*),.*:\s+(.*)\)", s) d = {'Наименование': r.group(1), 'ИНН': r.group(2), 'ОГРН': r.group(3)} In [88]: import re In [89]: pat = r'([^\(]*)\s+\(([^:\,\s]*):[\s]*(\d+)[\,\s]+([^:]*)[:\s]+([^\)]*)\)*' In [90]: m = re.search(pat, s, flags=re.U) In [91]: print(m.groups()) ('ООО "П.Б. Ромашка" ', 'ИНН', '00000000', 'ОГРН', '9999999') further task is trivial - to create a dictionary of the elements of a tuple ...
Where:
In [92]: s Out[92]: 'ООО "П.Б. Ромашка" (ИНН: 00000000, ОГРН: 9999999)' Source: https://ru.stackoverflow.com/questions/632694/
All Articles