Skip to content
Document Authoring DA  API Docs v1.10.0
npmGitHub

SearchFor

SearchFor = string | RegExp

Pattern type for searching content in documents.

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

String literal search (exact, case-sensitive):

// Find exact string "hello"
const result = textView.searchText("hello");

Case-insensitive word search:

// Find "hello" regardless of case, as a whole word
const result = textView.searchText(/\bhello\b/i);

Pattern matching with RegExp:

// Find all numbers
draft.replaceText(/\d+/g, (match) => {
return `[${match}]`;
});
// Find words starting with capital letter
const capitalWord = textView.searchText(/\b[A-Z][a-z]+\b/);

Search and replace with different patterns:

// Replace exact string
paragraph.replaceText("TODO", "DONE");
// Replace using pattern
paragraph.replaceText(/\bTODO\b/gi, "DONE");
// Find dates in MM/DD/YYYY format
const datePattern = /\b\d{2}/\d{2}/\d{4}\b/;
paragraph.replaceText(datePattern, (match) => ({
text: match,
formatting: { bold: true, color: "#0000ff" }
}));