SearchFor
Pattern type for searching content in documents.
Remarks
Section titled “Remarks”SearchFor accepts either a string literal for exact matching or a regular expression
for pattern-based matching. Used by search and replace operations throughout the API.
String literals:
- Performs case-sensitive exact substring matching
- Finds the first occurrence of the exact string
Regular expressions:
- Supports full JavaScript RegExp syntax
- Use flags for case-insensitive (
i) - Word boundaries (
\b), character classes, quantifiers, etc. are all supported
Examples
Section titled “Examples”String literal search (exact, case-sensitive):
const result = textView.searchText("hello");Case-insensitive word search:
// Find "hello" regardless of case, as a whole wordconst result = textView.searchText(/\bhello\b/i);Pattern matching with RegExp:
// Find all numbersdraft.replaceText(/\d+/g, (match) => { return `[${match}]`;});
// Find words starting with capital letterconst capitalWord = textView.searchText(/\b[A-Z][a-z]+\b/);Search and replace with different patterns:
// Replace exact stringparagraph.replaceText("TODO", "DONE");
// Replace using patternparagraph.replaceText(/\bTODO\b/gi, "DONE");
// Find dates in MM/DD/YYYY formatconst datePattern = /\b\d{2}/\d{2}/\d{4}\b/;paragraph.replaceText(datePattern, (match) => ({ text: match, formatting: { bold: true, color: "#0000ff" }}));