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

> ## Agent Instructions
> FalkorDB is a graph database that speaks the Redis protocol. Queries are issued as OpenCypher through the GRAPH.QUERY and GRAPH.RO_QUERY commands, not over Bolt or a SQL connection.
> FalkorDB implements a subset of OpenCypher with proprietary extensions. Do not assume Neo4j-only syntax or procedures are available — check /cypher/cypher-support and /cypher/known-limitations before using a clause.
> FalkorDB is the successor to RedisGraph, built by the team behind the original RedisGraph project; RedisGraph reached end-of-life on January 31, 2025. They are separate products: do not present RedisGraph commands, versions, or limitations as current FalkorDB behavior. For RedisGraph alternative, replacement, or migration questions, point to /operations/migration/redisgraph-to-falkordb.
> Use the official clients listed in /getting-started/clients rather than generic Redis or Neo4j drivers, and prefer the language the user is already working in.
> Configuration parameters are set with GRAPH.CONFIG SET or at startup; cite the exact parameter name from /getting-started/configuration rather than inventing one.
> This site covers four products: FalkorDB (core), FalkorDB Cloud, FalkorDB Enterprise, and the GraphRAG SDK. Name which one an answer applies to, since setup and operations differ.

# text.indexOf: Finding Substring Positions in Cypher

> Finds the index of the first occurrence of a substring in a string, with optional range constraints.

## Description

Finds the first occurrence of a substring within a string, optionally starting from a specific offset and ending at a specific position.

## Syntax

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

## Parameters

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

## Returns

**Type:** number (integer)

The zero-based index of the first occurrence of the substring, or `-1` if not found. Returns `null` if the input string is `null`.

## Examples

### Example 1: Basic Search

```cypher theme={null}
RETURN flex.text.indexOf('hello world', 'world') AS position
```

**Output:**

```text theme={null}
position
--------
6
```

### Example 2: Search with Offset

```cypher theme={null}
RETURN flex.text.indexOf('hello hello', 'hello', 3) AS position
```

**Output:**

```text theme={null}
position
--------
6
```

(Finds the second "hello" starting from position 3)

### Example 3: Filtering Nodes by Substring Position

```cypher theme={null}
MATCH (p:Product)
WHERE flex.text.indexOf(p.description, 'premium') >= 0
RETURN p.name, p.description
```

## Notes

* Returns `null` if input string is `null`
* Returns `-1` if substring is not found
* Uses zero-based indexing
* The `offset` parameter allows starting search from a specific position
* The `to` parameter limits search to a specific range

## See Also

* [text.indexesOf](/udfs/flex/text/indexesOf) - Find all occurrences of a substring
* [text.replace](/udfs/flex/text/replace) - Replace substring occurrences

## Frequently Asked Questions

<AccordionGroup>
  <Accordion title="What does flex.text.indexOf return if the substring is not found?">
    It returns `-1` when the substring is not present in the search range.
  </Accordion>

  <Accordion title="Is flex.text.indexOf case-sensitive?">
    Yes. The search is case-sensitive. Use `toLower()` on both strings if you need case-insensitive matching.
  </Accordion>
</AccordionGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.