> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.itential.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.itential.com/_mcp/server.

# search

> Use the search (string) task to find the index of the first regular expression match in a string.

The `search` task takes a regular expression and a string, then searches for the first match of the expression within the string. The task returns the index (position) where a match is found — indexing starts at zero. If no match is found, the task returns `-1`.

## Potential use case

Use `search` to check whether a certain pattern exists in a string and to find its position. In conjunction with the `substr` method, you can use `search` to find and replace text in a data record.

## Properties

| Input    | Type   | Description                                        |
| :------- | :----- | :------------------------------------------------- |
| `str`    | String | Required. The string to search.                    |
| `regexp` | String | Required. The regular expression pattern to match. |

| Output  | Type   | Description                                                                                                                                       |
| :------ | :----- | :------------------------------------------------------------------------------------------------------------------------------------------------ |
| `index` | Number | The position of the first match between the regular expression and the string. Returns `-1` if not found. The first character is at position `0`. |

## Example 1

In this example:

* `str` is statically set to `Hello World`.
* `regexp` is `or`.
* The `index` result is `7`, indicating the pattern `"or"` is located at position 7 in the string.

![](/_fern-img/74eb30e20114474b6bac07b38b589274eaae59d7d9240d7a3c6af551b1171abe.webp)![](/_fern-img/8e3c1e6b9326478b6708858fcba3cc8c2ca2291190b005e996cf88018e9060b6.webp)

## Example 2

In this example:

* `str` is `Hey Dr. Livingstone`.
* `regexp` is `\.`, a special character class notation indicating the match should be a period (`.`).
* The `index` result is `6`, indicating the period is located at position 6 in the string.

For more information, see [Using character classes in regular expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Character_Classes) on MDN.

![](/_fern-img/0b183489cbbbeb58d6234e60bae4f09df72e7eef3b9ff32708ab1410434f0c70.webp)![](/_fern-img/dc2846f0c3ac42b337aeb416242d08fa4344c7c2ab234835f60d0adf51014e43.webp)

## Example 3

In this example:

* `str` is `Hey Judey`.
* `regexp` is `\.`, indicating the match should be a period.
* Because no period exists in the string, the `index` result is `-1`.

![](/_fern-img/5b8276a82425e363c6f1f208b00416bc40bc5e3dc79f2cabce79af84b2b548ba.webp)![](/_fern-img/c56714dc0d4e593966718faf7ffa778e26ae3587924a900308beb6fee1ad81b1.webp)