> ## Documentation Index
> Fetch the complete documentation index at: https://new.docs.falkordb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# text.indexesOf

> Returns an array of all positions where a substring occurs in a string, with optional range constraints.

## Description

Finds all occurrences of a substring within a string, returning an array of all matching positions. Optionally search within a specific range.

## Syntax

```cypher theme={null}
flex.text.indexesOf(string, substring, from, to)
```

## Parameters

| Parameter   | Type   | Required | Description                                                     |
| ----------- | ------ | -------- | --------------------------------------------------------------- |
| `string`    | string | Yes      | The string to search in                                         |
| `substring` | string | Yes      | The substring to search for                                     |
| `from`      | number | No       | Starting position for search (default: 0)                       |
| `to`        | number | No       | Ending position for search (default: -1, meaning end of string) |

## Returns

**Type:** list of numbers

An array containing the zero-based indices of all occurrences of the substring. Returns an empty array if no matches are found. Returns `null` if the input string is `null`.

## Examples

### Example 1: Find All Occurrences

```cypher theme={null}
RETURN flex.text.indexesOf('hello hello hello', 'hello') AS positions
```

**Output:**

```text theme={null}
positions
-----------
[0, 6, 12]
```

### Example 2: Find Occurrences in Range

```cypher theme={null}
RETURN flex.text.indexesOf('abcabcabc', 'abc', 1, 9) AS positions
```

**Output:**

```text theme={null}
positions
---------
[3, 6]
```

(Skips first 'abc' at position 0, finds those within range)

### Example 3: Count Keyword Occurrences

```cypher theme={null}
MATCH (d:Document)
WITH d, flex.text.indexesOf(d.content, 'important') AS occurrences
WHERE size(occurrences) > 2
RETURN d.title, size(occurrences) AS importanceScore
ORDER BY importanceScore DESC
```

## Notes

* Returns `null` if input string is `null`
* Returns empty array if substring is not found
* Uses zero-based indexing
* The `from` parameter allows starting search from a specific position
* The `to` parameter limits search to a specific range
* Useful for counting occurrences or analyzing text patterns

## See Also

* [text.indexOf](/udfs/flex/text/indexOf) - Find first occurrence only
* [text.replace](/udfs/flex/text/replace) - Replace substring occurrences
* [text.regexGroups](/udfs/flex/text/regexGroups) - Find matches using regex patterns

## Frequently Asked Questions

<AccordionGroup>
  <Accordion title="What does flex.text.indexesOf return if no matches are found?">
    It returns an empty list `[]`.
  </Accordion>

  <Accordion title="Can I limit the search to a specific range?">
    Yes. Use the optional `from` and `to` parameters to restrict the search within a substring range.
  </Accordion>
</AccordionGroup>
