Functions for working with strings

**Syntax**

```
lengthUTF8(s)
```

**Aliases**: `CHARACTER_LENGTH`, `CHAR_LENGTH`

**Arguments**

- `s` — String containing valid UTF-8 encoded text. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Length of the string `s` in Unicode code points. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT lengthUTF8('Здравствуй, мир!')
```

```
┌─lengthUTF8('Здравствуй, мир!')─┐
│                             16 │
└────────────────────────────────┘
```

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

Introduced in: v1.1.0

Converts an ASCII string to lowercase.

**Syntax**

```
lower(s)
```

**Aliases**: `lcase`

**Arguments**

- `s` — A string to convert to lowercase. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns a lowercase string from `s`. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT lower('CLICKHOUSE')
```

```
┌─lower('CLICKHOUSE')─┐
│ clickhouse          │
└─────────────────────┘
```

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

Introduced in: v1.1.0

Converts a string to lowercase, assuming that the string contains valid UTF-8 encoded text. If this assumption is violated, no exception is thrown and the result is undefined.

**Syntax**

```
lowerUTF8(input)
```

**Arguments**

- `input` — Input string to convert to lowercase. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns a lowercase string. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**first**

```
SELECT lowerUTF8('München') as Lowerutf8;
```

```
münchen
```

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

Introduced in: v25.11.0

The function is used for natural sorting.

**Syntax**

```
naturalSortKey(s)
```

**Aliases**: `NATURAL_SORT_KEY`

**Arguments**

- `s` — A string to convert to natural sort key. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns a natural sort key string from `s`. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT s FROM t ORDER BY naturalSortKey(s)
```

```
┌─s───┐
│ a1  │
| a02 │
└─────┘
```

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

Introduced in: v21.11.0

Normalizes a UTF-8 string according to the [NFC normalization form](https://en.wikipedia.org/wiki/Unicode_equivalence#Normal_forms).

**Syntax**

```
normalizeUTF8NFC(str)
```

**Arguments**

- `str` — UTF-8 encoded input string. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns the NFC normalized form of the UTF-8 string. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT
'é' AS original, -- e + combining acute accent (U+0065 + U+0301)
length(original),
normalizeUTF8NFC('é') AS nfc_normalized, -- é (U+00E9)
length(nfc_normalized);
```

```
┌─original─┬─length(original)─┬─nfc_normalized─┬─length(nfc_normalized)─┐
│ é        │                2 │ é              │                      2 │
└──────────┴──────────────────┴────────────────┴────────────────────────┘
```

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

Introduced in: v21.11.0

Normalizes a UTF-8 string according to the [NFD normalization form](https://en.wikipedia.org/wiki/Unicode_equivalence#Normal_forms).

**Syntax**

```
normalizeUTF8NFD(str)
```

**Arguments**

- `str` — UTF-8 encoded input string. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns the NFD normalized form of the UTF-8 string. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT
    'é' AS original, -- é (U+00E9)
    length(original),
    normalizeUTF8NFD('é') AS nfd_normalized, -- e + combining acute (U+0065 + U+0301)
    length(nfd_normalized);
```

```
┌─original─┬─length(original)─┬─nfd_normalized─┬─length(nfd_normalized)─┐
│ é        │                2 │ é              │                      3 │
└──────────┴──────────────────┴────────────────┴────────────────────────┘
```

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

Introduced in: v21.11.0

Normalizes a UTF-8 string according to the [NFKC normalization form](https://en.wikipedia.org/wiki/Unicode_equivalence#Normal_forms).

**Syntax**

```
normalizeUTF8NFKC(str)
```

**Arguments**

- `str` — UTF-8 encoded input string. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns the NFKC normalized form of the UTF-8 string. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT
    '① ② ③' AS original,                            -- Circled number characters
    normalizeUTF8NFKC('① ② ③') AS nfkc_normalized;  -- Converts to 1 2 3
```

```
┌─original─┬─nfkc_normalized─┐
│ ① ② ③  │ 1 2 3           │
└──────────┴─────────────────┘
```

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

Introduced in: v26.3.0

Normalizes a UTF-8 string according to the [NFKC\_Casefold normalization form](https://unicode.org/reports/tr44/#NFKC_Casefold), which applies NFKC normalization and then case folding.
This is useful for case-insensitive matching of identifiers.

**Syntax**

```
normalizeUTF8NFKCCasefold(str)
```

**Arguments**

- `str` — UTF-8 encoded input string. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns the NFKC\_Casefold normalized form of the UTF-8 string. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT
    'Ä ① Hello' AS original,
    normalizeUTF8NFKCCasefold('Ä ① Hello') AS nfkc_cf_normalized;
```

```
┌─original───┬─nfkc_cf_normalized─┐
│ Ä ① Hello │ ä 1 hello           │
└────────────┴────────────────────┘
```

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

Introduced in: v21.11.0

Normalizes a UTF-8 string according to the [NFKD normalization form](https://en.wikipedia.org/wiki/Unicode_equivalence#Normal_forms).

**Syntax**

```
normalizeUTF8NFKD(str)
```

**Arguments**

- `str` — UTF-8 encoded input string. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns the NFKD normalized form of the UTF-8 string. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT
    'H₂O²' AS original,                            -- H + subscript 2 + O + superscript 2
    normalizeUTF8NFKD('H₂O²') AS nfkd_normalized;  -- Converts to H 2 O 2
```

```
┌─original─┬─nfkd_normalized─┐
│ H₂O²     │ H2O2            │
└──────────┴─────────────────┘
```

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

Introduced in: v24.1.0

Returns the UTF8-encoded plaintext of a [Punycode](https://en.wikipedia.org/wiki/Punycode)-encoded string.
If no valid Punycode-encoded string is given, an exception is thrown.

**Syntax**

```
punycodeDecode(s)
```

**Arguments**

- `s` — Punycode-encoded string. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns the plaintext of the input value. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT punycodeDecode('Mnchen-3ya')
```

```
┌─punycodeDecode('Mnchen-3ya')─┐
│ München                      │
└──────────────────────────────┘
```

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

Introduced in: v24.1.0

Returns the [Punycode](https://en.wikipedia.org/wiki/Punycode) representation of a string.
The string must be UTF8-encoded, otherwise the behavior is undefined.

**Syntax**

```
punycodeEncode(s)
```

**Arguments**

- `s` — Input value. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns a Punycode representation of the input value. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Usage example**

```
SELECT punycodeEncode('München')
```

```
┌─punycodeEncode('München')─┐
│ Mnchen-3ya                │
└───────────────────────────┘
```

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

Introduced in: v23.2.0