Run3 Extract and Replace Text in Word Document Runs
[COLM'26] SkillLearnBench is the first benchmark for evaluating continual learning methods that automatically generate agent skills.
npx -y skills add cxcscmu/SkillLearnBench --skill run3_Extract-and-Replace-Text-in-Word-Document-RunsAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
What its author says it does
Copied from the file, not written here
Use this skill to safely find and replace placeholder text in Word document paragraphs at the run level. This handles cases where placeholder text is split across multiple runs, which is common in Word documents and breaks simple string replacement.
SKILL.md
1.5 KB, as published. Nobody here has run it
Why This Matters
Word documents store text in "runs" — segments with the same formatting. A placeholder like {{CANDIDATE_FULL_NAME}} might be split as:
- Run 1:
{{CAND - Run 2:
IDATE_FULL - Run 3:
_NAME}}
Direct .replace() on paragraph.text won't find it.
Algorithm
def replace_placeholders_in_text(paragraph, replacements_dict):
# Reconstruct full text from all runs
full_text = ''.join(run.text for run in paragraph.runs)
# Apply all replacements to the full text
for pattern, value in replacements_dict.items():
full_text = re.sub(pattern, str(value), full_text)
# Clear all runs
for run in paragraph.runs:
run.text = ""
# If paragraph has no runs, create one
if not paragraph.runs:
paragraph.add_run(full_text)
else:
# Add full text to first run only
paragraph.runs[0].text = full_text
Key Details
- Use regex patterns for placeholders:
r'{{PLACEHOLDER_NAME}}' - Always reconstruct from all runs first—never iterate and modify runs simultaneously
- Escape literal dots in regex (e.g.,
\.not.) - Return
Trueif any replacement was made (useful for tracking)