import re from docx import Document from helpers import get_doc_blocks def get_fz93_doc(doc): fz93_docx = set() paragraphs = get_doc_blocks(doc) fz93_doc_regex = ["части 1 статьи 93 Федерального закона", "ч. 1 ст. 93", "частью 1 статьи 93 Федерального закона"] for docpara in paragraphs: for val in fz93_doc_regex: fz93_docx.update( re.findall(val, docpara) ) #doc = Document(file_name_doc) for table in doc.tables: for row in table.rows: for cell in row.cells: for para in cell.paragraphs: for val in fz93_doc_regex: fz93_docx.update( re.findall(val, para.text) ) return fz93_docx