Functions for Searching in Strings

**Returned value**

Returns `1`, if there was at least one case-insensitive match, otherwise `0`, if there was not at least one case-insensitive match. [`UInt8`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Case insensitive search**

```
SELECT multiSearchAnyCaseInsensitive('ClickHouse',['c','h'])
```

```
┌─multiSearchAnyCaseInsensitive('ClickHouse', ['c', 'h'])─┐
│                                                       1 │
└─────────────────────────────────────────────────────────┘
```

## multiSearchAnyCaseInsensitiveUTF8[​](#multiSearchAnyCaseInsensitiveUTF8 "Direct link to multiSearchAnyCaseInsensitiveUTF8")

Introduced in: v20.1.0

Like [multiSearchAnyUTF8](#multiSearchAnyUTF8) but ignores case.

**Syntax**

```
multiSearchAnyCaseInsensitiveUTF8(haystack, [needle1, needle2, ..., needleN])
```

**Arguments**

- `haystack` — UTF-8 string in which the search is performed. [`String`](/docs/sql-reference/data-types/string)
- `needle` — UTF-8 substrings to be searched. [`Array(String)`](/docs/sql-reference/data-types/array)

**Returned value**

Returns `1`, if there was at least one case-insensitive match, otherwise `0`, if there was not at least one case-insensitive match. [`UInt8`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Given a UTF-8 string 'Здравствуйте', check if character 'з' (lowercase) is present**

```
SELECT multiSearchAnyCaseInsensitiveUTF8('Здравствуйте',['з'])
```

```
┌─multiSearchA⋯те', ['з'])─┐
│                        1 │
└──────────────────────────┘
```

## multiSearchAnyUTF8[​](#multiSearchAnyUTF8 "Direct link to multiSearchAnyUTF8")

Introduced in: v20.1.0

Like [multiSearchAny](#multiSearchAny) but assumes `haystack` and the `needle` substrings are UTF-8 encoded strings.

**Syntax**

```
multiSearchAnyUTF8(haystack, [needle1, needle2, ..., needleN])
```

**Arguments**

- `haystack` — UTF-8 string in which the search is performed. [`String`](/docs/sql-reference/data-types/string)
- `needle` — UTF-8 substrings to be searched. [`Array(String)`](/docs/sql-reference/data-types/array)

**Returned value**

Returns `1`, if there was at least one match, otherwise `0`, if there was not at least one match. [`UInt8`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Given '你好，世界' ('Hello, world') as a UTF-8 string, check if there are any 你 or 界 characters in the string**

```
SELECT multiSearchAnyUTF8('你好，世界', ['你', '界'])
```

```
┌─multiSearchA⋯你', '界'])─┐
│                        1 │
└──────────────────────────┘
```

## multiSearchFirstIndex[​](#multiSearchFirstIndex "Direct link to multiSearchFirstIndex")

Introduced in: v20.1.0

Searches for multiple needle strings in a haystack string (case-sensitive) and returns the 1-based index of the first needle found.

**Syntax**

```
multiSearchFirstIndex(haystack, [needle1, needle2, ..., needleN])
```

**Arguments**

- `haystack` — The string to search in. [`String`](/docs/sql-reference/data-types/string)
- `needles` — Array of strings to search for. [`Array(String)`](/docs/sql-reference/data-types/array)

**Returned value**

Returns the 1-based index (position in the needles array) of the first needle found in the haystack. Returns 0 if no needles are found. The search is case-sensitive. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT multiSearchFirstIndex('ClickHouse Database', ['Click', 'Database', 'Server']);
```

```
┌─multiSearchF⋯ 'Server'])─┐
│                        1 │
└──────────────────────────┘
```

**Case-sensitive behavior**

```
SELECT multiSearchFirstIndex('ClickHouse Database', ['CLICK', 'Database', 'Server']);
```

```
┌─multiSearchF⋯ 'Server'])─┐
│                        2 │
└──────────────────────────┘
```

**No match found**

```
SELECT multiSearchFirstIndex('Hello World', ['goodbye', 'test']);
```

```
┌─multiSearchF⋯', 'test'])─┐
│                        0 │
└──────────────────────────┘
```

## multiSearchFirstIndexCaseInsensitive[​](#multiSearchFirstIndexCaseInsensitive "Direct link to multiSearchFirstIndexCaseInsensitive")

Introduced in: v20.1.0

Returns the index `i` (starting from 1) of the leftmost found needle\_i in the string `haystack` and 0 otherwise.
Ignores case.

**Syntax**

```
multiSearchFirstIndexCaseInsensitive(haystack, [needle1, needle2, ..., needleN]
```

**Arguments**

- `haystack` — String in which the search is performed. [`String`](/docs/sql-reference/data-types/string)
- `needle` — Substrings to be searched. [`Array(String)`](/docs/sql-reference/data-types/array)

**Returned value**

Returns the index (starting from 1) of the leftmost found needle. Otherwise `0`, if there was no match. [`UInt8`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT multiSearchFirstIndexCaseInsensitive('hElLo WoRlD', ['World', 'Hello']);
```

```
┌─multiSearchF⋯, 'Hello'])─┐
│                        1 │
└──────────────────────────┘
```

## multiSearchFirstIndexCaseInsensitiveUTF8[​](#multiSearchFirstIndexCaseInsensitiveUTF8 "Direct link to multiSearchFirstIndexCaseInsensitiveUTF8")

Introduced in: v20.1.0

Searches for multiple needle strings in a haystack string, case-insensitively with UTF-8 encoding support, and returns the 1-based index of the first needle found.

**Syntax**

```
multiSearchFirstIndexCaseInsensitiveUTF8(haystack, [needle1, needle2, ..., needleN])
```

**Arguments**

- `haystack` — The string to search in. [`String`](/docs/sql-reference/data-types/string)
- `needles` — Array of strings to search for. [`Array(String)`](/docs/sql-reference/data-types/array)

**Returned value**

Returns the 1-based index (position in the needles array) of the first needle found in the haystack. Returns 0 if no needles are found. The search is case-insensitive and respects UTF-8 character encoding. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT multiSearchFirstIndexCaseInsensitiveUTF8('ClickHouse Database', ['CLICK', 'data', 'server']);
```

```
┌─multiSearchF⋯ 'server'])─┐
│                        1 │
└──────────────────────────┘
```

**UTF-8 case handling**

```
SELECT multiSearchFirstIndexCaseInsensitiveUTF8('Привет Мир', ['мир', 'ПРИВЕТ']);
```

```
┌─multiSearchF⋯ 'ПРИВЕТ'])─┐
│                        1 │
└──────────────────────────┘
```

**No match found**

```
SELECT multiSearchFirstIndexCaseInsensitiveUTF8('Hello World', ['goodbye', 'test']);
```

```
┌─multiSearchF⋯', 'test'])─┐
│                        0 │
└──────────────────────────┘
```

## multiSearchFirstIndexUTF8[​](#multiSearchFirstIndexUTF8 "Direct link to multiSearchFirstIndexUTF8")

Introduced in: v20.1.0

Returns the index `i` (starting from 1) of the leftmost found needle\_i in the string `haystack` and 0 otherwise.
Assumes `haystack` and `needle` are UTF-8 encoded strings.

**Syntax**

```
multiSearchFirstIndexUTF8(haystack, [needle1, needle2, ..., needleN])
```

**Arguments**

- `haystack` — UTF-8 string in which the search is performed. [`String`](/docs/sql-reference/data-types/string)
- `needle` — Array of UTF-8 substrings to be searched. [`Array(String)`](/docs/sql-reference/data-types/array)

**Returned value**

Returns the index (starting from 1) of the leftmost found needle. Otherwise 0, if there was no match. [`UInt8`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT multiSearchFirstIndexUTF8('Здравствуйте мир', ['мир', 'здравствуйте']);
```

```
┌─multiSearchF⋯вствуйте'])─┐
│                        1 │
└──────────────────────────┘
```

## multiSearchFirstPosition[​](#multiSearchFirstPosition "Direct link to multiSearchFirstPosition")

Introduced in: v20.1.0

Like [`position`](#position) but returns the leftmost offset in a `haystack` string which matches any of multiple `needle` strings.

Functions [`multiSearchFirstPositionCaseInsensitive`](#multiSearchFirstPositionCaseInsensitive), [`multiSearchFirstPositionUTF8`](#multiSearchFirstPositionUTF8) and [`multiSearchFirstPositionCaseInsensitiveUTF8`](#multiSearchFirstPositionCaseInsensitiveUTF8) provide case-insensitive and/or UTF-8 variants of this function.

**Syntax**