Skip to content

Commit

Permalink
Add the introduction of capture group for regexp function (#16800)
Browse files Browse the repository at this point in the history
  • Loading branch information
xzhangxian1008 authored Mar 29, 2024
1 parent cb80cfb commit e00a620
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions functions-and-operators/string-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1507,9 +1507,15 @@ The difference between TiDB and MySQL support for the binary string type:

### Other compatibility

The difference between TiDB and MySQL support in replacing empty strings:
- The behavior of replacing empty strings in TiDB is different from MySQL. Taking `REGEXP_REPLACE("", "^$", "123")` as an example:

The following takes `REGEXP_REPLACE("", "^$", "123")` as an example:
- MySQL does not replace the empty string and returns `""` as the result.
- TiDB replaces the empty string and returns `"123"` as the result.

- MySQL does not replace the empty string and returns `""` as the result.
- TiDB replaces the empty string and returns `"123"` as the result.
- The keyword used for capturing groups in TiDB is different from MySQL. MySQL uses `$` as the keyword, while TiDB uses `\\` as the keyword. In addition, TiDB only supports capturing groups numbered from `0` to `9`.

For example, the following SQL statement returns `ab` in TiDB:

```sql
SELECT REGEXP_REPLACE('abcd','(.*)(.{2})$','\\1') AS s;
```

0 comments on commit e00a620

Please sign in to comment.