find
Search Word .docx files for text or regex patterns, returning paragraph ranges with context, totals, and a cursor for paging matches.
Instructions
Find text or a regex; matches come back as paragraph ranges, capped, with a cursor. The first page also gives total (or total_at_least and more: true when the time budget stopped the count). query_word is the query as typed in Word's Find box (^p, ^l, ^t, ^s, ^^; null past 255 characters, with ignore_accents or with a soft or no-break hyphen in the query; not for a regex; null at a folded match_level), with query_word_options (match_case, whole_words) to tick there.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| doc | Yes | Path to the .docx file. | |
| limit | No | Most matches to return; more are reached with `cursor`. | |
| query | Yes | Text to find (at most 1000 characters), or a Python regex if `regex`. | |
| regex | No | Treat `query` as a regex. | |
| cursor | No | The `next` value of the previous page. | |
| context | No | Characters of surrounding text on each side of a match. | |
| stories | No | Stories to read (default ["body"]): "notes" adds footnotes and endnotes, each after the paragraph holding its mark; "headers" adds headers and footers, after the body. Their addresses carry a prefix (fn3/p1#…, hdr1.default/p1#…). | |
| whole_word | No | Match only whole words (no letter, digit or mark on either side). | |
| ignore_case | No | Ignore case. | |
| match_level | No | Fold a literal query: `default` ignores case, accents and punctuation (symbols such as `$` still count), `loose` drops symbols too; `exact` is the search as without it. When passed, Word's Find codes (^p, ^t, ^l, ^s, ^-, ^~, ^uNNN, ^^) in `query` are read as their characters and each match gains `match_level`, the strictest level it meets. Not with `regex` (unless `exact`), nor with `ignore_case` or `ignore_accents` false at a folded level. Two meanings of exact: plain `find` (no `match_level`) matches the query as typed, flags as given, ^ codes literal, and its matches carry no level; `match_level: "exact"` keeps that text rule but reads the ^ codes and tags every match. A match's own `match_level` is `exact` only when it equals the query character for character (`case` when only case differs). | |
| ignore_accents | No | Ignore accents: `maria` finds `María`. A regex must be written without accents then. |