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
ti-chi-bot authored Apr 4, 2024
1 parent 54d3458 commit 2074aa8
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 @@ -110,9 +110,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 2074aa8

Please sign in to comment.