mysql regex_replace:如何在替换中使用regex组
问题描述:
有一张桌子:
| id | Name |
|----------------------|
| 1 |test1 test1 test1|
| 2 |test2 test2 test2|
想选择第一个正则表达式组(使用第一个单词来简化),所以我的查询是:
Want to select 1st regex group (used 1st word to simplify), so my query:
SELECT regexp_replace(name, "^([[:alnum:]]+)[[:space:]].*$","$1") FROM table;
结果:
|test1 |
|test1test2 |
那么结果如何累积呢?以及如何避免它并仍然可以使用正则表达式组?
So how it comes that result is accumulated? And how to avoid it and still be able to use regex group?
UPD : Mysql版本:8.0.11,MySQL社区服务器-GPL
UPD: Mysql version: 8.0.11, MySQL Community Server - GPL
答
https://bugs.mysql.com/bug.php?id=90803 -5月21日:
已在8.0.12中修复.
Fixed in 8.0.12.
REGEXP_RELACE()来自一个结果集行的结果可以结转 到下一行,从而导致之前结果的累积 当前行.
REGEXP_RELACE() results from one result set row could carry forward to the next row, resulting in accumulation of previous results in the current row.