[Python] Detect specific pattern regex python

Discussão em 'Python' iniciado por Stack, Junho 30, 2025.

  1. Stack

    Stack Membro Participativo

    I want to find all the occurrences of an specific term (and its variations) in a word document.

    1. Extracted the text from the word document
    2. Try to find pattern via regex

    The pattern consists of words that start with DOC- and after the - there are 9 digits.

    I have tried the following without success:

    document variable is the extracted text with the following function:

    import docx

    def getText(filename):
    doc = docx.Document(filename)
    fullText = []
    for para in doc.paragraphs:
    fullText.append(para.text)
    return '\n'.join(fullText)

    1. pattern = re.compile('^DOC.\d{9}$')
    2. pattern.findall(document)

    pattern.findall(document)

    Can someone help me?

    Thanks in advance

    Continue reading...

Compartilhe esta Página