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

# regexp_replace

> 将匹配正则表达式的子字符串替换为指定字符串。

对字符串 str 进行正则匹配，将命中 pattern 的部分使用 repl 来进行替换。

### 语法

```Haskell theme={null}
regexp_replace(str, pattern, repl)
```

## 参数说明

`str`: 支持的数据类型为 VARCHAR。

`pattern`: 支持的数据类型为 VARCHAR。

`repl`: 支持的数据类型为 VARCHAR。

## 返回值说明

返回值的数据类型为 VARCHAR。

## 示例

```Plain Text theme={null}
MySQL > SELECT regexp_replace('a b c', " ", "-");
+-----------------------------------+
| regexp_replace('a b c', ' ', '-') |
+-----------------------------------+
| a-b-c                             |
+-----------------------------------+

MySQL > SELECT regexp_replace('a b c','(b)','<\\1>');
+----------------------------------------+
| regexp_replace('a b c', '(b)', '<\1>') |
+----------------------------------------+
| a <b> c                                |
+----------------------------------------+
```


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