for paragraph in doc.paragraphs: matches = re.finditer(pattern, paragraph.text) for match in matches: start, end = match.start(2), match.end(2) inline = paragraph.runs before = paragraph.text[:start] italic_text = paragraph.text[start:end] after = paragraph.text[end:] paragraph.clear() if before: paragraph.add_run(before) italic_run = paragraph.add_run(italic_text) italic_run.italic = True if after: paragraph.add_run(after)