Skip to main content

Find In Text

Uncontrolled node

Overview

The Find In Text node searches for a substring (pattern) within a text string and returns the character position (index) where the pattern is found. It supports both forward and backward searching, with an optional offset to start the search from a specific position.

When Backwards is disabled (default), the node searches forward from the start of the text using indexOf. When enabled, it searches backward from the end using lastIndexOf. If the pattern is not found, the node returns -1.

Inputs

InputTypeDescriptionDefault
TextTextThe text content to search within. This input must be connected from another node.-
PatternTextThe substring to search for within the text. Can be set via the properties panel or connected as an input.-
OffsetNumberThe character position to start searching from. For forward searches, this is the starting index; for backward searches, this is the index to search backwards from.0 (forward) or end of text (backward)

Properties

PropertyTypeDescriptionDefault
BackwardsBooleanWhen enabled, searches from the end of the text backwards using lastIndexOf. When disabled, searches forward from the start using indexOf.false

Outputs

OutputTypeDescription
PositionNumberThe character index where the pattern is found (0-based). Returns -1 if the pattern is not found.

Runtime Behavior and Defaults

  • Forward Search (Backwards = false): Uses JavaScript's indexOf method. If no offset is provided, the search starts from index 0.
  • Backward Search (Backwards = true): Uses JavaScript's lastIndexOf method. If no offset is provided, the search starts from the end of the string (effectively searching the entire text).
  • Offset Handling:
    • For forward searches, the offset specifies the starting position (inclusive).
    • For backward searches, the offset specifies the position to search backwards from (exclusive of characters after this index).
    • If the offset is negative or not a number, it defaults to 0 for forward searches.
  • Case Sensitivity: The search is case-sensitive. To perform case-insensitive searches, convert both the text and pattern to the same case using the Text Change Case node before passing them to Find In Text.
  • Empty Pattern: If the pattern is an empty string, indexOf returns 0 (start of text) and lastIndexOf returns the length of the text.

Example

Basic forward search:

  • Text: "The quick brown fox jumps over the lazy dog"
  • Pattern: "fox"
  • Backwards: false
  • Output Position: 16 (the "f" in "fox" starts at character index 16)

Backward search (finding last occurrence):

  • Text: "The quick brown fox jumps over the lazy dog"
  • Pattern: "the"
  • Backwards: true
  • Output Position: 31 (finds the "the" in "lazy dog", not the "The" at position 0)

Using an offset to skip matches:

  • Text: "Hello world, hello universe"
  • Pattern: "hello"
  • Offset: 10
  • Backwards: false
  • Output Position: 13 (finds the second "hello" after position 10, skipping the first "Hello" at position 0 due to case sensitivity)